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")

[((11, 13, 11, 35), 'wtforms.SubmitField', 'SubmitField', ({(11, 25, 11, 34): '"""Sign Up"""'}, {}), "('Sign Up')", False, 'from wtforms import StringField, PasswordField, SubmitField\n'), ((22, 13, 22, 35), 'wtforms.SubmitField', 'SubmitField', ({(22, 25, 22, 34): '"""Sign In"""'}, {}), "('Sign In')", False, 'from wtforms import StringField, PasswordField, SubmitField\n'), ((16, 18, 16, 64), 'wtforms.validators.ValidationError', 'ValidationError', ({(16, 34, 16, 63): '"""The username already exists"""'}, {}), "('The username already exists')", False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), ((8, 58, 8, 73), 'wtforms.validators.InputRequired', 'InputRequired', ({}, {}), '()', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), ((8, 75, 8, 82), 'wtforms.validators.Email', 'Email', ({}, {}), '()', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), ((9, 62, 9, 77), 'wtforms.validators.InputRequired', 'InputRequired', ({}, {}), '()', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), ((10, 53, 10, 68), 'wtforms.validators.InputRequired', 'InputRequired', ({}, {}), '()', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), ((14, 28, 14, 72), 'models.User.query.filter_by', 'User.query.filter_by', (), '', False, 'from models import User\n'), ((20, 61, 20, 76), 'wtforms.validators.InputRequired', 'InputRequired', ({}, {}), '()', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), ((21, 59, 21, 74), 'wtforms.validators.InputRequired', 'InputRequired', ({}, {}), '()', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n')]