from flask_wtf import FlaskForm from wtforms import StringField, PasswordField, SubmitField, BooleanField from wtforms.validators import DataRequired, Email, ValidationError from advlabdb.models import User class RegistrationForm(FlaskForm): email = StringField("Email", validators=[DataRequired(), Email()]) assistant = BooleanField("Assistant", default=True) admin = BooleanField("Admin", default=False) submit = SubmitField("Register") def validate_email(form, field): user = User.query.filter_by(email=field.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")