-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.py
56 lines (48 loc) · 1.67 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
56
from wtforms import (
StringField,
PasswordField,
BooleanField,
IntegerField,
DateField,
TextAreaField,
)
from flask_wtf import FlaskForm
from wtforms.validators import InputRequired, Length, EqualTo, Email, Regexp ,Optional
import email_validator
from flask_login import current_user
from wtforms import ValidationError,validators
from models import User
class login_form(FlaskForm):
email = StringField(validators=[InputRequired(), Email(), Length(1, 64)])
pwd = PasswordField(validators=[InputRequired(), Length(min=8, max=72)])
# Placeholder labels to enable form rendering
username = StringField(
validators=[Optional()]
)
class register_form(FlaskForm):
username = StringField(
validators=[
InputRequired(),
Length(3, 20, message="Please provide a valid name"),
Regexp(
"^[A-Za-z][A-Za-z0-9_.]*$",
0,
"Usernames must have only letters, " "numbers, dots or underscores",
),
]
)
email = StringField(validators=[InputRequired(), Email(), Length(1, 64)])
pwd = PasswordField(validators=[InputRequired(), Length(8, 72)])
cpwd = PasswordField(
validators=[
InputRequired(),
Length(8, 72),
EqualTo("pwd", message="Passwords must match !"),
]
)
def validate_email(self, email):
if User.query.filter_by(email=email.data).first():
raise ValidationError("Email already registered!")
def validate_uname(self, uname):
if User.query.filter_by(username=username.data).first():
raise ValidationError("Username already taken!")