forked from hack4impact/flask-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
119 lines (100 loc) · 3.9 KB
/
forms.py
File metadata and controls
119 lines (100 loc) · 3.9 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from flask import url_for
from flask_wtf import Form
from wtforms import ValidationError
from wtforms.fields import (
BooleanField,
PasswordField,
StringField,
SubmitField,
)
from wtforms.fields.html5 import EmailField
from wtforms.validators import Email, EqualTo, InputRequired, Length
from app.models import User
class LoginForm(Form):
email = EmailField(
'Email', validators=[InputRequired(),
Length(1, 64),
Email()])
password = PasswordField('Password', validators=[InputRequired()])
remember_me = BooleanField('Keep me logged in')
submit = SubmitField('Log in')
class RegistrationForm(Form):
first_name = StringField(
'First name', validators=[InputRequired(),
Length(1, 64)])
last_name = StringField(
'Last name', validators=[InputRequired(),
Length(1, 64)])
email = EmailField(
'Email', validators=[InputRequired(),
Length(1, 64),
Email()])
password = PasswordField(
'Password',
validators=[
InputRequired(),
EqualTo('password2', 'Passwords must match')
])
password2 = PasswordField('Confirm password', validators=[InputRequired()])
submit = SubmitField('Register')
def validate_email(self, field):
if User.query.filter_by(email=field.data).first():
raise ValidationError('Email already registered. (Did you mean to '
'<a href="{}">log in</a> instead?)'.format(
url_for('account.login')))
class RequestResetPasswordForm(Form):
email = EmailField(
'Email', validators=[InputRequired(),
Length(1, 64),
Email()])
submit = SubmitField('Reset password')
# We don't validate the email address so we don't confirm to attackers
# that an account with the given email exists.
class ResetPasswordForm(Form):
email = EmailField(
'Email', validators=[InputRequired(),
Length(1, 64),
Email()])
new_password = PasswordField(
'New password',
validators=[
InputRequired(),
EqualTo('new_password2', 'Passwords must match.')
])
new_password2 = PasswordField(
'Confirm new password', validators=[InputRequired()])
submit = SubmitField('Reset password')
def validate_email(self, field):
if User.query.filter_by(email=field.data).first() is None:
raise ValidationError('Unknown email address.')
class CreatePasswordForm(Form):
password = PasswordField(
'Password',
validators=[
InputRequired(),
EqualTo('password2', 'Passwords must match.')
])
password2 = PasswordField(
'Confirm new password', validators=[InputRequired()])
submit = SubmitField('Set password')
class ChangePasswordForm(Form):
old_password = PasswordField('Old password', validators=[InputRequired()])
new_password = PasswordField(
'New password',
validators=[
InputRequired(),
EqualTo('new_password2', 'Passwords must match.')
])
new_password2 = PasswordField(
'Confirm new password', validators=[InputRequired()])
submit = SubmitField('Update password')
class ChangeEmailForm(Form):
email = EmailField(
'New email', validators=[InputRequired(),
Length(1, 64),
Email()])
password = PasswordField('Password', validators=[InputRequired()])
submit = SubmitField('Update email')
def validate_email(self, field):
if User.query.filter_by(email=field.data).first():
raise ValidationError('Email already registered.')