nopaque/app/settings/forms.py

77 lines
2.0 KiB
Python
Raw Normal View History

from flask_wtf import FlaskForm
from wtforms import (
BooleanField,
2022-11-29 15:46:33 +00:00
FileField,
PasswordField,
SelectField,
StringField,
SubmitField,
2022-11-29 15:46:33 +00:00
TextAreaField,
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
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()
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=[('', 'Choose your option')],
validators=[DataRequired()]
)
2022-09-02 11:07:30 +00:00
submit = SubmitField()
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-11-29 15:46:33 +00:00
class EditPrivacySettingsForm(FlaskForm):
2022-12-05 08:40:02 +00:00
private_profile = BooleanField(
'Private profile'
)
private_email = BooleanField(
'Private email'
2022-11-29 15:46:33 +00:00
)
2022-12-05 08:40:02 +00:00
only_username = BooleanField(
'Show only username'
)
2022-11-29 15:46:33 +00:00
submit = SubmitField()