2020-10-23 11:52:01 +00:00
|
|
|
from flask_wtf import FlaskForm
|
2022-02-08 11:26:20 +00:00
|
|
|
from wtforms import (
|
|
|
|
BooleanField,
|
2022-11-29 15:46:33 +00:00
|
|
|
FileField,
|
2022-02-08 11:26:20 +00:00
|
|
|
PasswordField,
|
|
|
|
SelectField,
|
|
|
|
StringField,
|
|
|
|
SubmitField,
|
2022-11-29 15:46:33 +00:00
|
|
|
TextAreaField,
|
2022-02-08 11:26:20 +00:00
|
|
|
ValidationError
|
|
|
|
)
|
2022-09-02 11:07:30 +00:00
|
|
|
from wtforms.validators import (
|
|
|
|
DataRequired,
|
|
|
|
InputRequired,
|
|
|
|
Email,
|
|
|
|
EqualTo,
|
|
|
|
Length,
|
|
|
|
Regexp
|
|
|
|
)
|
|
|
|
from app.models import User, UserSettingJobStatusMailNotificationLevel
|
|
|
|
from app.auth import USERNAME_REGEX
|
2020-10-23 11:52:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ChangePasswordForm(FlaskForm):
|
|
|
|
password = PasswordField('Old password', validators=[DataRequired()])
|
2022-09-02 11:07:30 +00:00
|
|
|
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()
|
2020-10-23 11:52:01 +00:00
|
|
|
|
2021-09-13 14:36:48 +00:00
|
|
|
def __init__(self, user, *args, **kwargs):
|
2020-10-23 11:52:01 +00:00
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.user = user
|
|
|
|
|
|
|
|
def validate_current_password(self, field):
|
|
|
|
if not self.user.verify_password(field.data):
|
2022-02-08 11:26:20 +00:00
|
|
|
raise ValidationError('Invalid password')
|
2020-10-23 11:52:01 +00:00
|
|
|
|
|
|
|
class EditNotificationSettingsForm(FlaskForm):
|
2022-02-08 11:26:20 +00:00
|
|
|
job_status_mail_notification_level = SelectField(
|
|
|
|
'Job status mail notification level',
|
|
|
|
choices=[('', 'Choose your option')],
|
|
|
|
validators=[DataRequired()]
|
|
|
|
)
|
2022-09-02 11:07:30 +00:00
|
|
|
submit = SubmitField()
|
2022-02-08 11:26:20 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.job_status_mail_notification_level.choices += [
|
2022-09-02 11:07:30 +00:00
|
|
|
(x.name, x.name.capitalize())
|
|
|
|
for x in UserSettingJobStatusMailNotificationLevel
|
2022-02-08 11:26:20 +00:00
|
|
|
]
|
2022-11-29 15:46:33 +00:00
|
|
|
|