-
Notifications
You must be signed in to change notification settings - Fork 0
/
Forms.py
32 lines (22 loc) · 1.36 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
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, BooleanField, PasswordField
from wtforms.validators import DataRequired, Email, Length, EqualTo
class LoginForm(FlaskForm):
"""
WTForms is an instrument which makes working with forms easier
It can:
- Check the data;
- Create form errors;
- Save data storage on a server (CSRF protection)
Each field on a form has its own class from WTForms (e.g. StringField, PasswordField ...)
"""
username = StringField('Username: ', validators=[DataRequired(), Length(4, max=20)])
password = PasswordField('Password: ', validators=[DataRequired(), Length(4, max=100, message='Password must be between 4 and 100 symbols!')])
remember_me_button = BooleanField('Remember Me: ', default=False)
submit_button = SubmitField('Login')
class RegisterForm(FlaskForm):
username = StringField('Username: ', validators=[DataRequired(), Length(4, max=20)])
email = StringField('Email: ', validators=[DataRequired(), Email('Invalid Email!')])
password_1 = PasswordField('Password: ', validators=[DataRequired(), Length(4, max=100, message='Password must be between 4 and 100 symbols!')])
password_2 = PasswordField('Repeat Password: ', validators=[DataRequired(), EqualTo('password_1', message="Passwords Don't Match!")])
submit_button = SubmitField('SignUp')