-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
65 lines (47 loc) · 1.86 KB
/
forms.py
File metadata and controls
65 lines (47 loc) · 1.86 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
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, TextAreaField
from wtforms.validators import Length, Regexp, DataRequired, EqualTo, Email
from wtforms import ValidationError
from models import User
from database import db
class RegisterForm(FlaskForm):
class Meta:
csrf = False
firstname = StringField('First Name', validators=[Length(1, 10)])
lastname = StringField('Last Name', validators=[Length(1, 20)])
email = StringField('Email', [
Email(message='Not a valid email address.'),
DataRequired()])
password = PasswordField('Password', [
DataRequired(message="Please enter a password."),
EqualTo('confirmPassword', message='Passwords must match')
])
confirmPassword = PasswordField('Confirm Password', validators=[
Length(min=6, max=10)
])
submit = SubmitField('Submit')
def validate_email(self, field):
if db.session.query(User).filter_by(email=field.data).count() != 0:
raise ValidationError('Username already in use.')
class LoginForm(FlaskForm):
class Meta:
csrf = False
email = StringField('Email', [
Email(message='Not a valid email address.'),
DataRequired()])
password = PasswordField('Password', [
DataRequired(message="Please enter a password.")])
submit = SubmitField('Submit')
def validate_email(self, field):
if db.session.query(User).filter_by(email=field.data).count() == 0:
raise ValidationError('Incorrect username or password.')
class CommentForm(FlaskForm):
class Meta:
csrf = False
comment = TextAreaField('Comment',validators=[Length(min=1)])
submit = SubmitField('Add Comment')
submit1 = SubmitField('Report')
class ReportForm(FlaskForm):
class Meta:
csrf = False
comment1 = TextAreaField('Comment')