mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
39 lines
1.4 KiB
Python
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.')
|