-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforms.py
144 lines (115 loc) · 4.87 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from wtforms.validators import InputRequired, Email, Length, ValidationError
from flask_wtf import FlaskForm
from wtforms import (StringField, PasswordField, SubmitField,
RadioField, IntegerField, TextAreaField, SelectField)
from flask_wtf.file import FileField, FileRequired, FileAllowed
from models.categories import Category
from models.database import Database
from string import punctuation
def checkForJunk(form = None, field = None, usrtext= None):
punct = punctuation.replace('_', '')
if not field:
field = {'data': usrtext}
for i in field.data:
if i in punct:
if usrtext:
return True
else:
raise ValidationError(
'Only Alphabets, Numbers and Underscores Allowed!')
def StrongPassword(form, field):
punct = punctuation
numbers = "0123456789"
alphabets = "QWERTYUIOPASDFGHJKLZXCVBNM"
errors = {
"isSpecial": 'Special Symbol',
"isNumber": 'Number',
'isUpper': 'UpperCase Character'
}
if any(char in field.data for char in punct):
errors.pop('isSpecial')
if any(char in field.data for char in numbers):
errors.pop('isNumber')
if any(char in field.data for char in alphabets):
errors.pop('isUpper')
if errors:
message = "Password Must Contain atleast 1 "
errors = [errors[msg] for msg in errors]
extra = ", ".join(errors[:-1])
if extra:
extra2 = " and " + errors[-1]
else:
extra2 = errors[-1]
message += extra + extra2
raise ValidationError(message)
class SignupForm(FlaskForm):
name = StringField("Name",
validators=[
InputRequired('Please Enter your Name'),
checkForJunk
], render_kw={"placeholder": "Martha Jones"})
email = StringField("Email",
validators=[
InputRequired('Please Enter your Email'),
Email('Please Enter a valid email address')
], render_kw={
"placeholder": "marthajones@example.com"})
password = PasswordField("Password",
validators=[
InputRequired('Please Enter your Password'),
Length(min=6, max=16,
message='Password Must be 8-16\
Characters Long'), StrongPassword],
render_kw={"placeholder": "******"})
gender = RadioField("Gender",
choices=[
('M', 'Male'),
('F', 'Female'),
('O', 'Other')],
validators=[
InputRequired('Please Select a Gender')
])
age = IntegerField('Age', validators=[
InputRequired('Please Enter a Valid Age')],
render_kw={
"placeholder": "23"})
submit = SubmitField("Signup",
validators=[
InputRequired()
])
class LoginForm(FlaskForm):
username = StringField("Email/Username",
validators=[
InputRequired(
'Please Enter your Username Or Email'),
Length(min=4, max=50,
message='Invalid Username')],
render_kw={"placeholder": "Martha_Jones96"})
password = PasswordField("Password",
validators=[
InputRequired('Please Enter your Password'),
Length(min=6, max=16,
message='Invalid Password')],
render_kw={"placeholder": "******"})
submit = SubmitField("Login",
validators=[
InputRequired()
])
Database.initialize('Atypical')
categories = Category.getAllCategories(True)
categories = [(cat, cat) for cat in categories]
# print(categories)
class UploadForm(FlaskForm):
photo = FileField('Upload your Picture', validators=[
FileRequired('File not selected!'),
FileAllowed(['jpg', 'png','jpeg'], 'Images only!')
])
# category = SelectField("Category",
# choices=categories,
# validators=[
# InputRequired('Please Choose a Category')])
description = TextAreaField('Description')
submit = SubmitField("Upload",
validators=[
InputRequired()
])