Repository navigation
Expand file tree
/
Copy pathform.py
More file actions
80 lines (67 loc) · 4.04 KB
/
Copy pathform.py
File metadata and controls
80 lines (67 loc) · 4.04 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
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileRequired, FileAllowed, FileSize
from wtforms import StringField, PasswordField, EmailField, SubmitField, BooleanField, TextAreaField
from wtforms.validators import DataRequired, Email, Length, EqualTo, ValidationError
from wtforms import validators
from sqlalchemy import select
from models import *
class RegistrationForm(FlaskForm):
username = StringField('Username', validators=[DataRequired(), Length(min=2,max=19)])
fullname = StringField('Full Name', validators=[DataRequired(), Length(min=2,max=19)])
email = EmailField('Email Address', validators=[DataRequired(),Email()])
password = PasswordField('New Password', validators=[DataRequired()])
confirm_password = PasswordField("Repeat the Password",validators=[DataRequired(), EqualTo('password')])
submit = SubmitField("Sign Up")
def validate_username(self, username):
result = db.session.execute(select(User.username).where(User.username == username.data)).all()
if result:
raise ValidationError(f"The username {username.data} is taken, please choose a different one")
if " " in username.data:
raise ValidationError("Username cannot contain spaces")
def validate_email(self, email):
result = db.session.execute(select(User.username).where(User.email == email.data)).all()
if result:
raise ValidationError(f"The email {email.data} is already used, please choose a different one")
def validate_fullname(self, fullname):
if "<Mod>" in fullname.data:
raise ValidationError("You cannot put <Mod> in your fullname.")
class LoginForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()] )
remember = BooleanField("Remember Me")
submit = SubmitField("Login")
class RequestResetForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
submit = SubmitField("Submit")
class ResetPasswordForm(FlaskForm):
password = PasswordField('New Password', validators=[DataRequired()])
confirm_password = PasswordField("Repeat the Password", validators=[DataRequired(), EqualTo('password')])
submit = SubmitField("Reset")
class PostForm(FlaskForm):
title = StringField('Add Post Title',validators=[DataRequired()])
content = TextAreaField("Write down your thoughts !",validators=[DataRequired()])
photo = FileField("image", validators=[validators.Optional(),
FileAllowed(['jpg', 'gif', 'jpeg', 'png'], 'Please choose jpg, png or gif!'),
FileSize(max_size=2*1024*1024, message="File must be under 2MB")
])
submit = SubmitField("Submit")
class CommentForm(FlaskForm):
text = TextAreaField("",validators=[DataRequired()])
submit = SubmitField("Submit")
class EditProfileForm(FlaskForm):
fullname = StringField('Full Name', validators=[Length(min=0, max=140)])
submit = SubmitField('Submit')
email = EmailField('Email Address', validators=[validators.Optional(),Email()])
password = PasswordField('New Password', validators=[])
confirm_password = PasswordField("Repeat the Password", validators=[EqualTo('password')])
photo = FileField("Profile Picture", validators=[validators.Optional(),
FileAllowed(['jpg', 'jpeg', 'png'], 'Please choose jpg or png!'),
FileSize(max_size=2 * 1024 * 1024, message="File must be under 2MB")
])
def validate_email(self, email):
result = db.session.execute(select(User.username).where(User.email == email.data)).all()
if result:
raise ValidationError(f"The email {email.data} is already used, please choose a different one")
def validate_fullname(self, fullname):
if "<Mod>" in fullname.data:
raise ValidationError("You cannot put <Mod> in your fullname.")