from flask_wtf import FlaskForm from wtforms import StringField, PasswordField, SubmitField, BooleanField from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError from advlabdb.models import User class RegistrationForm(FlaskForm): email = StringField("Email", validators=[DataRequired(), Email()]) admin = BooleanField("Admin", default=False) submit = SubmitField("Register") def validate_email(self, email): user = User.query.filter_by(email=email.data.lower()).first() if user: raise ValidationError("A user with this email address is already registered!") class LoginForm(FlaskForm): email = StringField("Email", validators=[DataRequired(), Email()]) password = PasswordField("Password", validators=[DataRequired()]) submit = SubmitField("Login")