-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebforms.py
More file actions
58 lines (48 loc) · 2.62 KB
/
webforms.py
File metadata and controls
58 lines (48 loc) · 2.62 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
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, BooleanField, TextAreaField, validators
from wtforms.validators import DataRequired, EqualTo, Length, Email, ValidationError
from wtforms.widgets import TextArea
from flask_ckeditor import CKEditorField
from flask_wtf.file import FileField
# Create Search Form
class SearchForm(FlaskForm):
searched = StringField("Searched", validators=[DataRequired()])
submit = SubmitField("Submit")
# Create Login Form
class LoginForm(FlaskForm):
username = StringField("Username", validators=[DataRequired()])
password = PasswordField("Password", validators=[DataRequired()])
submit = SubmitField("Login")
# Create a Posts Form
class PostForm(FlaskForm):
title = StringField("Title", validators=[DataRequired()])
# content = StringField("Content", validators=[DataRequired()], widget=TextArea())
content = CKEditorField('Content', validators=[DataRequired()])
slug = StringField("Slug", validators=[DataRequired()])
submit = SubmitField("Submit")
# Create a UserForm Class
class UserForm(FlaskForm):
name = StringField("Name", validators=[DataRequired(), validators.Length(min=2, max=40), validators.Regexp(r'^[A-Za-z\s]*$', message='Invalid name, Only letters are allowed')])
username = StringField("Username", validators=[DataRequired(), Length(max=64)])
email = StringField("Email", validators=[DataRequired(), Email(), Length(max=120)])
favorite_color = StringField("Favorite Color")
about_author = TextAreaField("About Author")
profile_pic = FileField("Profile Pic")
password_hash = PasswordField("Password", validators=[DataRequired(), Length(min=8, message='Password should be at least %(min)d characters long'), EqualTo('password_hash2', message='Passwords Must Match!')])
password_hash2 = PasswordField('Confirm Password', validators=[DataRequired()])
submit = SubmitField("Submit")
# you can use validators.email() instead of Email()
def validate_username(self, username):
excluded_chars = " *?!'^+%&/()=}][{$#"
for char in self.username.data:
if char in excluded_chars:
raise ValidationError(f"Character {char} is not allowed in username.")
# Create a PasswordForm class
class PasswordForm(FlaskForm):
email = StringField("What's your email", validators=[DataRequired()])
password_hash = PasswordField("What's your password", validators=[DataRequired()])
submit = SubmitField("Submit")
# Create a NamerForm Class
class NamerForm(FlaskForm):
name = StringField("What's your name", validators=[DataRequired()])
submit = SubmitField("Submit")