mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-26 11:24:18 +00:00
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from flask_wtf import FlaskForm
|
|
from wtforms import PasswordField, SelectField, SubmitField, ValidationError
|
|
from wtforms.validators import DataRequired, EqualTo
|
|
from app.models import UserSettingJobStatusMailNotificationLevel
|
|
|
|
|
|
class ChangePasswordForm(FlaskForm):
|
|
password = PasswordField('Old password', validators=[DataRequired()])
|
|
new_password = PasswordField(
|
|
'New password',
|
|
validators=[
|
|
DataRequired(),
|
|
EqualTo('new_password_2', message='Passwords must match')
|
|
]
|
|
)
|
|
new_password_2 = PasswordField(
|
|
'New password confirmation',
|
|
validators=[
|
|
DataRequired(),
|
|
EqualTo('new_password', message='Passwords must match')
|
|
]
|
|
)
|
|
submit = SubmitField()
|
|
|
|
def __init__(self, user, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.user = user
|
|
|
|
def validate_current_password(self, field):
|
|
if not self.user.verify_password(field.data):
|
|
raise ValidationError('Invalid password')
|
|
|
|
|
|
class EditNotificationSettingsForm(FlaskForm):
|
|
job_status_mail_notification_level = SelectField(
|
|
'Job status mail notification level',
|
|
choices=[
|
|
(x.name, x.name.capitalize())
|
|
for x in UserSettingJobStatusMailNotificationLevel
|
|
],
|
|
validators=[DataRequired()]
|
|
)
|
|
submit = SubmitField()
|