|
|
@ -4,6 +4,7 @@ from wtforms import StringField, PasswordField, IntegerField, SubmitField |
|
|
|
from wtforms.fields.html5 import DateField |
|
|
|
from wtforms.validators import DataRequired, Length, EqualTo, InputRequired, \ |
|
|
|
ValidationError, NumberRange, Optional |
|
|
|
from datetime import date |
|
|
|
|
|
|
|
from db import get_registration_code, get_registered_user |
|
|
|
|
|
|
@ -30,6 +31,11 @@ def username_availability_validator(form: FlaskForm, field): |
|
|
|
raise ValidationError("Username already registered!") |
|
|
|
|
|
|
|
|
|
|
|
def registration_code_expiration_date_validator(form: FlaskForm, field): |
|
|
|
if field.data <= date.today(): |
|
|
|
raise ValidationError("Expiration Date must be in the future!") |
|
|
|
|
|
|
|
|
|
|
|
class RegistrationForm(FlaskForm): |
|
|
|
username = StringField( |
|
|
|
'Username', |
|
|
@ -56,7 +62,9 @@ class LoginForm(FlaskForm): |
|
|
|
|
|
|
|
|
|
|
|
class RegistrationCodeForm(FlaskForm): |
|
|
|
expiration_time = DateField('Expiration Time', format='%Y-%m-%d', validators=[Optional()]) |
|
|
|
expiration_time = DateField('Expiration Time', |
|
|
|
format='%Y-%m-%d', |
|
|
|
validators=[Optional(), registration_code_expiration_date_validator]) |
|
|
|
max_usages = IntegerField('Max Usages', validators=[NumberRange(min=1)]) |
|
|
|
|
|
|
|
|
|
|
|