-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathforms.py
More file actions
55 lines (48 loc) · 1.81 KB
/
Copy pathforms.py
File metadata and controls
55 lines (48 loc) · 1.81 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
"""
This module gives information about forms
! validate couldn't be a static method
"""
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField
from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError
from db_connect import mongo
class RegistrationForm(FlaskForm):
"""
This Form used in registration
"""
username = StringField('Username',
validators=[DataRequired(), Length(min=2, max=50)])
email = StringField('Email',
validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired(), Length(min=5, max=50)])
confirm_password = PasswordField('Confirm Password',
validators=[DataRequired(), EqualTo('password')])
submit = SubmitField('Sign Up')
def validate_username(self, username):
"""
Check username is not used earlier
:param username: str
:return: None
"""
user = mongo.db.users.find_one({'name': username.data})
if user:
print(user)
raise ValidationError('This username already taken. Please, choose another one')
def validate_email(self, email):
"""
Check email is not used earlier
:param email: str
:return: None
"""
user = mongo.db.users.find_one({'email': email.data})
if user:
raise ValidationError('This email already taken. Please, choose another one')
class LoginForm(FlaskForm):
"""
This Form used end Login User
"""
email = StringField('Email',
validators=[DataRequired(), Email()])
password = PasswordField('Password',
validators=[DataRequired()])
submit = SubmitField('Login')