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, 'wtforms.SubmitField', 'SubmitField', False, 'from wtforms import StringField, PasswordField, SubmitField\n'), (22, 'wtforms.SubmitField', 'SubmitField', False, 'from wtforms import StringField, PasswordField, SubmitField\n'), (16, 'wtforms.validators.ValidationError', 'ValidationError', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), (8, 'wtforms.validators.InputRequired', 'InputRequired', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), (8, 'wtforms.validators.Email', 'Email', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), (9, 'wtforms.validators.InputRequired', 'InputRequired', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), (10, 'wtforms.validators.InputRequired', 'InputRequired', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), (14, 'models.User.query.filter_by', 'User.query.filter_by', False, 'from models import User\n'), (20, 'wtforms.validators.InputRequired', 'InputRequired', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n'), (21, 'wtforms.validators.InputRequired', 'InputRequired', False, 'from wtforms.validators import InputRequired, Email, ValidationError\n')]