2017-03-08 13:53:09 -05:00
|
|
|
from flask_wtf import FlaskForm, RecaptchaField
|
|
|
|
|
|
|
|
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField
|
|
|
|
from wtforms import validators, ValidationError
|
|
|
|
from wtforms.fields.html5 import EmailField
|
|
|
|
from ..models import User
|
|
|
|
|
|
|
|
|
|
|
|
class LoginForm(FlaskForm):
|
2018-02-20 05:17:28 -05:00
|
|
|
email = EmailField('E-Mail', [validators.DataRequired(), validators.Length(1,64), validators.Email()])
|
|
|
|
password = PasswordField('Password', [validators.DataRequired(), validators.Length(1,128)])
|
|
|
|
remember_me = BooleanField('Remember me ?')
|
2017-03-08 13:53:09 -05:00
|
|
|
#recaptcha = RecaptchaField()
|
2018-02-20 05:17:28 -05:00
|
|
|
submit = SubmitField('Login')
|
2017-03-08 13:53:09 -05:00
|
|
|
|
|
|
|
class TwoFAForm(FlaskForm):
|
|
|
|
token = StringField('Token', [validators.DataRequired(), validators.Length(6, 6)])
|
2018-02-20 05:17:28 -05:00
|
|
|
submit = SubmitField('Confirm')
|
2017-03-08 13:53:09 -05:00
|
|
|
|
|
|
|
class RegistrationForm(FlaskForm):
|
2018-02-20 05:17:28 -05:00
|
|
|
email = StringField('E-Mail', [validators.DataRequired(), validators.Length(6,35), validators.Email()])
|
2017-03-08 13:53:09 -05:00
|
|
|
def validate_email(self, field):
|
|
|
|
if User.query.filter_by(email=field.data).first():
|
2018-02-20 05:17:28 -05:00
|
|
|
raise ValidationError('Error. Please try again.')
|
|
|
|
password = PasswordField('Password', [validators.DataRequired(), validators.EqualTo('confirm', message='Both passwords must be equal')])
|
|
|
|
confirm = PasswordField('Your password again', [validators.DataRequired()])
|
|
|
|
accept_tos = BooleanField('I accept the <a href="/terms">Terms of Service</a>', [validators.DataRequired()])
|
2017-03-08 13:53:09 -05:00
|
|
|
recaptcha = RecaptchaField()
|
2018-02-20 05:17:28 -05:00
|
|
|
submit = SubmitField('REGISTER')
|
2017-03-08 13:53:09 -05:00
|
|
|
|
|
|
|
class ChangePasswordForm(FlaskForm):
|
2018-02-20 05:17:28 -05:00
|
|
|
old_password = PasswordField('Old Password', [validators.DataRequired()])
|
|
|
|
password = PasswordField('New Password', [validators.DataRequired(), validators.EqualTo('confirm', message='Both passwords must be equal')])
|
|
|
|
confirm = PasswordField('Your password again')
|
|
|
|
submit = SubmitField('Renew Password')
|
2017-03-08 13:53:09 -05:00
|
|
|
|
|
|
|
class PasswordResetRequestForm(FlaskForm):
|
2018-02-20 05:17:28 -05:00
|
|
|
email = EmailField('E-Mail', [validators.DataRequired(), validators.Length(1,64), validators.Email()])
|
2017-03-08 13:53:09 -05:00
|
|
|
recaptcha = RecaptchaField()
|
2018-02-20 05:17:28 -05:00
|
|
|
submit = SubmitField('Reset password', [validators.DataRequired()])
|
2017-03-08 13:53:09 -05:00
|
|
|
|
|
|
|
class PasswordResetForm(FlaskForm):
|
2018-02-20 05:17:28 -05:00
|
|
|
email = EmailField('E-Mail', [validators.DataRequired(), validators.Length(1,64), validators.Email()])
|
|
|
|
password = PasswordField('Password', [validators.DataRequired(), validators.EqualTo('confirm', message='Both password fields must be equal')])
|
|
|
|
confirm = PasswordField('Your password again', [validators.DataRequired()])
|
|
|
|
submit = SubmitField('Change password')
|
2017-03-08 13:53:09 -05:00
|
|
|
|
|
|
|
def validate_email(self, field):
|
|
|
|
if User.query.filter_by(email=field.data).first() is None:
|
2018-02-20 05:17:28 -05:00
|
|
|
raise ValidationError('Error. Please try again.')
|
2017-03-08 13:53:09 -05:00
|
|
|
|