2020-10-11 21:30:11 +00:00
|
|
|
from flask_wtf import FlaskForm
|
|
|
|
from wtforms import StringField, PasswordField, SubmitField
|
|
|
|
from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError
|
2021-02-06 04:52:46 +00:00
|
|
|
from core import User
|
2020-10-11 21:30:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RegisterForm(FlaskForm):
|
|
|
|
username = StringField('Username', validators=[DataRequired(), Length(min=4, max=24)])
|
2021-02-06 04:52:46 +00:00
|
|
|
email = StringField('Email', validators=[DataRequired(), Email()])
|
2020-10-11 21:30:11 +00:00
|
|
|
password = PasswordField('Password', validators=[DataRequired(), Length(min=8)])
|
|
|
|
confirm_password = PasswordField('Confirm Password',
|
|
|
|
validators=[DataRequired(), EqualTo('password', message="Passwords must match!")])
|
|
|
|
submit = SubmitField("Sign Up")
|
|
|
|
|
|
|
|
def validate_username(self, username):
|
2021-02-06 04:52:46 +00:00
|
|
|
user = User.query.filter_by(username=username.data).first()
|
|
|
|
if user:
|
|
|
|
raise ValidationError("User exists already! Please use a different name!")
|
|
|
|
|
|
|
|
|
|
|
|
class LoginForm(FlaskForm):
|
|
|
|
username = StringField('Username', validators=[DataRequired(), Length(min=4, max=24)])
|
|
|
|
password = PasswordField('Password', validators=[DataRequired(), Length(min=8, max=32)])
|
|
|
|
submit = SubmitField("Login")
|