2019-11-12 12:36:22 +00:00
|
|
|
from app.models import User
|
2019-09-23 14:11:01 +00:00
|
|
|
from flask_wtf import FlaskForm
|
2019-10-09 14:10:30 +00:00
|
|
|
from wtforms import (PasswordField, StringField, SubmitField,
|
|
|
|
ValidationError, BooleanField)
|
2019-10-31 12:19:18 +00:00
|
|
|
from wtforms.validators import DataRequired, EqualTo, Email
|
|
|
|
|
2019-09-23 14:11:01 +00:00
|
|
|
|
|
|
|
class ChangePasswordForm(FlaskForm):
|
|
|
|
"""
|
|
|
|
Form to change information of currently logged in User. User can change
|
|
|
|
informations about him on his own.
|
|
|
|
"""
|
|
|
|
old_password = PasswordField('Old password', validators=[DataRequired()])
|
|
|
|
new_password = PasswordField(
|
|
|
|
'New password',
|
|
|
|
validators=[DataRequired(),
|
|
|
|
EqualTo('new_password2', message='Passwords must match.')]
|
|
|
|
)
|
|
|
|
new_password2 = PasswordField(
|
|
|
|
'Confirm new password',
|
|
|
|
validators=[DataRequired(),
|
|
|
|
EqualTo('new_password', message='Passwords must match.')]
|
|
|
|
)
|
|
|
|
submit = SubmitField('Update Password')
|
|
|
|
|
|
|
|
|
|
|
|
class EditProfileForm(FlaskForm):
|
|
|
|
email = StringField('Change Email',
|
2019-10-30 14:16:37 +00:00
|
|
|
validators=[Email(), DataRequired()])
|
2019-09-23 14:11:01 +00:00
|
|
|
submit = SubmitField('Change Email')
|
|
|
|
|
|
|
|
def __init__(self, user, *args, **kwargs):
|
|
|
|
super(EditProfileForm, self).__init__(*args, **kwargs)
|
|
|
|
self.user = user
|
|
|
|
|
|
|
|
def validate_email(self, field):
|
|
|
|
if field.data != self.user.email and \
|
|
|
|
User.query.filter_by(email=field.data).first():
|
|
|
|
raise ValidationError('Email already registered!')
|
2019-10-09 14:10:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EditUserSettingsForm(FlaskForm):
|
|
|
|
is_dark = BooleanField('Dark Mode')
|
|
|
|
submit = SubmitField('Save Settings')
|