-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.py
55 lines (48 loc) · 1.8 KB
/
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
from flask_wtf import FlaskForm
from flask_wtf.recaptcha import RecaptchaField
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import ValidationError, DataRequired, Email, EqualTo, Length
import sqlalchemy as sa
from db.schema import User, db
from local_config import config
class LoginForm(FlaskForm):
username = StringField("Username", validators=[DataRequired()])
password = PasswordField("Password", validators=[DataRequired()])
submit = SubmitField("Sign In")
class RegistrationForm(FlaskForm):
username = StringField(
"Username",
validators=[
DataRequired(),
Length(
min=6, max=14, message="Username must be between 6 and 14 characters."
),
],
)
email = StringField("Email", validators=[DataRequired(), Email()])
password = PasswordField(
"Password",
validators=[
DataRequired(),
Length(
min=6, max=14, message="Password must be between 6 and 14 characters."
),
],
)
password2 = PasswordField(
"Repeat Password", validators=[DataRequired(), EqualTo("password")]
)
recaptcha = RecaptchaField()
submit = SubmitField("Register")
def validate_username(self, username):
user = User.query.filter_by(username=username.data).first()
if user is not None:
raise ValidationError(
"Username already exists. Please use a different username."
)
def validate_email(self, email):
user = User.query.filter_by(email=email.data).first()
if user is not None:
raise ValidationError(
"Email address already has an associated account. Please use a different email address."
)