nopaque/app/profile/forms.py

39 lines
1.4 KiB
Python
Raw Normal View History

from flask_wtf import FlaskForm
2020-02-19 13:49:52 +00:00
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()])
2020-02-20 09:03:42 +00:00
save_email = SubmitField('Save email')
2020-02-19 13:49:52 +00:00
class EditGeneralSettingsForm(FlaskForm):
dark_mode = BooleanField('Dark mode')
2020-02-20 09:03:42 +00:00
save_settings = SubmitField('Save settings')
2020-02-19 13:49:52 +00:00
class EditPasswordForm(FlaskForm):
current_password = PasswordField('Current password',
validators=[DataRequired()])
password = PasswordField(
'New password',
2020-02-19 13:49:52 +00:00
validators=[DataRequired(), EqualTo('password_confirmation',
message='Passwords must match.')]
)
2020-02-19 13:49:52 +00:00
password_confirmation = PasswordField(
'Password confirmation',
validators=[DataRequired(),
2020-02-19 13:49:52 +00:00
EqualTo('password', message='Passwords must match.')]
)
2020-02-20 09:03:42 +00:00
save_password = SubmitField('Save password')
def __init__(self, user, *args, **kwargs):
2020-02-19 13:49:52 +00:00
super(EditPasswordForm, self).__init__(*args, **kwargs)
self.user = user
2020-02-19 13:49:52 +00:00
def validate_current_password(self, field):
if not self.user.verify_password(field.data):
raise ValidationError('Invalid password.')