-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_forms.py
80 lines (56 loc) · 2.96 KB
/
web_forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, EmailField, BooleanField
from wtforms.validators import InputRequired, Length, ValidationError, DataRequired, Email, EqualTo
from web_models import User
password_min = 6
password_max = 20
username_min = 1
username_max = 20
class RegisterForm(FlaskForm):
username = StringField(validators=[
InputRequired(), Length(min=username_min, max=username_max)], render_kw={"placeholder": "Username"})
email = EmailField(validators=[
InputRequired()], render_kw={"placeholder": "Email"})
password = PasswordField(validators=[
InputRequired(), Length(min=password_min, max=password_max)], render_kw={"placeholder": "Password"})
submit = SubmitField('Register')
def validate_email(self, email):
existing_user_email = User.query.filter_by(
email=email.data).first()
if existing_user_email:
# print("Email already exists")
raise ValidationError(
'That email already exists. Please choose a different one.')
class LoginForm(FlaskForm):
email = EmailField(validators=[
InputRequired()], render_kw={"placeholder": "Email"})
password = PasswordField(validators=[
InputRequired()], render_kw={"placeholder": "Password"})
remember = BooleanField('Remember Me')
submit = SubmitField('Login')
class RequestResetForm(FlaskForm):
email = EmailField('Email',
validators=[DataRequired(), Email()], render_kw={"placeholder": "Email"})
submit = SubmitField('Request Password Reset')
def validate_email(self, email):
existing_user_email = User.query.filter_by(email=email.data).first()
if existing_user_email is None:
# print("Email does not exist")
raise ValidationError(
'There is no account with that email. You must register first.')
class ResetPasswordForm(FlaskForm):
password = PasswordField('Password', validators=[DataRequired(), Length(min=password_min, max=password_max)], render_kw={
"placeholder": "New Password"})
confirm_password = PasswordField('Confirm Password',
validators=[DataRequired(), EqualTo('password'), Length(min=password_min, max=password_max)], render_kw={"placeholder": "Confirm Password"})
submit = SubmitField('Reset Password')
class RequestVerificationForm(FlaskForm):
email = EmailField('Email',
validators=[DataRequired(), Email()], render_kw={"placeholder": "Email"})
submit = SubmitField('Verify Email')
def validate_email(self, email):
existing_user_email = User.query.filter_by(email=email.data).first()
if existing_user_email is None:
# print("Email does not exist")
raise ValidationError(
'There is no account with that email. You must register first.')