-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms.py
34 lines (28 loc) · 1.39 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
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, RadioField, SelectField
from wtforms.validators import ValidationError, DataRequired, Email, EqualTo, InputRequired
from models import User
class LoginForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()])
remember_me = BooleanField('Ricordami')
submit = SubmitField('Entra')
class RegistrationForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
password2 = PasswordField(
'Ripeti la Password', validators=[DataRequired(), EqualTo('password')])
submit = SubmitField('Registrati')
def validate_username(self, username):
user = User.query.filter_by(username=username.data).first()
if user is not None:
raise ValidationError('Username già registrato.')
def validate_email(self, email):
user = User.query.filter_by(email=email.data).first()
if user is not None:
raise ValidationError('Email già registrata.')
class CreateTestForm(FlaskForm):
submit = SubmitField('Crea test')
class TestForm(FlaskForm):
submit = SubmitField('Avanti')