2019-09-23 14:11:01 +00:00
|
|
|
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()])
|
|
|
|
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(
|
2019-09-23 14:11:01 +00:00
|
|
|
'New password',
|
2020-02-19 13:49:52 +00:00
|
|
|
validators=[DataRequired(), EqualTo('password_confirmation',
|
|
|
|
message='Passwords must match.')]
|
2019-09-23 14:11:01 +00:00
|
|
|
)
|
2020-02-19 13:49:52 +00:00
|
|
|
password_confirmation = PasswordField(
|
|
|
|
'Password confirmation',
|
2019-09-23 14:11:01 +00:00
|
|
|
validators=[DataRequired(),
|
2020-02-19 13:49:52 +00:00
|
|
|
EqualTo('password', message='Passwords must match.')]
|
2019-09-23 14:11:01 +00:00
|
|
|
)
|
2020-02-19 13:49:52 +00:00
|
|
|
save_password = SubmitField('Save Password')
|
2019-09-23 14:11:01 +00:00
|
|
|
|
|
|
|
def __init__(self, user, *args, **kwargs):
|
2020-02-19 13:49:52 +00:00
|
|
|
super(EditPasswordForm, self).__init__(*args, **kwargs)
|
2019-09-23 14:11:01 +00:00
|
|
|
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.')
|