from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField
from wtforms.validators import InputRequired, Email, ValidationError
from models import User


class RegistrationForm(FlaskForm):
    email = StringField('Your Email Address', validators=[InputRequired(), Email()])
    username = StringField('Enter your username', validators=[InputRequired()])
    password = PasswordField('Password', validators=[InputRequired()])
    submit = SubmitField('Sign Up')

    def validate_username(self, username):
        existing_username = User.query.filter_by(username=username.data).first()
        if existing_username:
            raise ValidationError("The username already exists")


class LoginForm(FlaskForm):
    username = StringField("Your email address", validators=[InputRequired()])
    password = PasswordField("Your password:", validators=[InputRequired()])
    submit = SubmitField("Sign In")

[((471, 493), 'wtforms.SubmitField', 'SubmitField', (['"""Sign Up"""'], {}), "('Sign Up')\n", (482, 493), False, 'from wtforms import StringField, PasswordField, SubmitField\n'), ((913, 935), 'wtforms.SubmitField', 'SubmitField', (['"""Sign In"""'], {}), "('Sign In')\n", (924, 935), False, 'from wtforms import StringField, PasswordField, SubmitField\n'), ((667, 713), 'wtforms.validators.ValidationError', 'ValidationError', (['"""The username already exists"""'], {}), "('The username already exists')\n", (682, 713), False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), ((280, 295), 'wtforms.validators.InputRequired', 'InputRequired', ([], {}), '()\n', (293, 295), False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), ((297, 304), 'wtforms.validators.Email', 'Email', ([], {}), '()\n', (302, 304), False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), ((369, 384), 'wtforms.validators.InputRequired', 'InputRequired', ([], {}), '()\n', (382, 384), False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), ((440, 455), 'wtforms.validators.InputRequired', 'InputRequired', ([], {}), '()\n', (453, 455), False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), ((566, 610), 'models.User.query.filter_by', 'User.query.filter_by', ([], {'username': 'username.data'}), '(username=username.data)\n', (586, 610), False, 'from models import User\n'), ((805, 820), 'wtforms.validators.InputRequired', 'InputRequired', ([], {}), '()\n', (818, 820), False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), ((882, 897), 'wtforms.validators.InputRequired', 'InputRequired', ([], {}), '()\n', (895, 897), False, 'from wtforms.validators import InputRequired, Email, ValidationError\n')]