nopaque/app/profile/forms.py
2020-02-19 14:49:52 +01:00

39 lines
1.4 KiB
Python

from flask_wtf import FlaskForm
from wtforms import (BooleanField, PasswordField, StringField, SubmitField,
ValidationError)
from wtforms.validators import DataRequired, Email, EqualTo
class EditEmailForm(FlaskForm):
email = StringField('New email', validators=[Email(), DataRequired()])
save_email = SubmitField('Save Email')
class EditGeneralSettingsForm(FlaskForm):
dark_mode = BooleanField('Dark mode')
save_settings = SubmitField('Save Settings')
class EditPasswordForm(FlaskForm):
current_password = PasswordField('Current password',
validators=[DataRequired()])
password = PasswordField(
'New password',
validators=[DataRequired(), EqualTo('password_confirmation',
message='Passwords must match.')]
)
password_confirmation = PasswordField(
'Password confirmation',
validators=[DataRequired(),
EqualTo('password', message='Passwords must match.')]
)
save_password = SubmitField('Save Password')
def __init__(self, user, *args, **kwargs):
super(EditPasswordForm, self).__init__(*args, **kwargs)
self.user = user
def validate_current_password(self, field):
if not self.user.verify_password(field.data):
raise ValidationError('Invalid password.')