from flask_wtf import FlaskForm from wtforms import (BooleanField, PasswordField, SelectField, 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') job_status_mail_notifications = SelectField( 'Job status mail notifications', choices=[('', 'Choose your option'), ('all', 'Notify on all status changes'), ('end', 'Notify only when a job ended'), ('none', 'No status update notifications')], validators=[DataRequired()]) job_status_site_notifications = SelectField( 'Job status site notifications', choices=[('', 'Choose your option'), ('all', 'Notify on all status changes'), ('end', 'Notify only when a job ended'), ('none', 'No status update notifications')], validators=[DataRequired()]) 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.')