proxadmin/app/auth/forms.py

52 lines
2.6 KiB
Python
Raw Normal View History

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):
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()
submit = SubmitField('Login')
2017-03-08 13:53:09 -05:00
class TwoFAForm(FlaskForm):
token = StringField('Token', [validators.DataRequired(), validators.Length(6, 6)])
submit = SubmitField('Confirm')
2017-03-08 13:53:09 -05:00
class RegistrationForm(FlaskForm):
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():
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()
submit = SubmitField('REGISTER')
2017-03-08 13:53:09 -05:00
class ChangePasswordForm(FlaskForm):
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):
email = EmailField('E-Mail', [validators.DataRequired(), validators.Length(1,64), validators.Email()])
2017-03-08 13:53:09 -05:00
recaptcha = RecaptchaField()
submit = SubmitField('Reset password', [validators.DataRequired()])
2017-03-08 13:53:09 -05:00
class PasswordResetForm(FlaskForm):
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:
raise ValidationError('Error. Please try again.')
2017-03-08 13:53:09 -05:00