mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 09:15:41 +00:00
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
|
from flask_wtf import FlaskForm
|
||
|
from wtforms import PasswordField, StringField, SubmitField, ValidationError
|
||
|
from wtforms.validators import DataRequired, EqualTo, Length
|
||
|
from ..models import User
|
||
|
|
||
|
|
||
|
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',
|
||
|
validators=[Length(0, 254), DataRequired()])
|
||
|
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!')
|