2021-03-31 23:04:21 +00:00
|
|
|
from flask_wtf import FlaskForm
|
|
|
|
from wtforms import StringField, PasswordField, SubmitField, BooleanField
|
2021-04-01 22:33:50 +00:00
|
|
|
from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError
|
|
|
|
from advlabdb.models import User
|
2021-03-31 23:04:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RegistrationForm(FlaskForm):
|
|
|
|
email = StringField("Email",
|
|
|
|
validators=[DataRequired(), Email()])
|
|
|
|
admin = BooleanField("Admin")
|
|
|
|
submit = SubmitField("Sign Up")
|
|
|
|
|
2021-04-01 22:33:50 +00:00
|
|
|
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!")
|
|
|
|
|
2021-03-31 23:04:21 +00:00
|
|
|
|
|
|
|
class LoginForm(FlaskForm):
|
|
|
|
email = StringField("Email",
|
|
|
|
validators=[DataRequired(), Email()])
|
|
|
|
password = PasswordField("Password", validators=[DataRequired()])
|
|
|
|
submit = SubmitField("Login")
|