mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-12 09:00:40 +00:00
Add change profile page.
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, PasswordField, BooleanField, SubmitField
|
||||
from wtforms.validators import DataRequired, Length, Email, Regexp, EqualTo
|
||||
from wtforms.validators import DataRequired, Length, Email, Regexp, EqualTo, Optional
|
||||
from wtforms import ValidationError
|
||||
from ..models import User
|
||||
|
||||
@ -48,6 +48,22 @@ class PasswordResetRequestForm(FlaskForm):
|
||||
|
||||
|
||||
class ChangeProfileForm(FlaskForm):
|
||||
email = StringField('Email', validators=[DataRequired(), Length(1, 64),
|
||||
email = StringField('Email', validators=[Optional(), Length(1, 64),
|
||||
Email()])
|
||||
username = StringField('Username', validators=[
|
||||
Optional(), Length(1, 64),
|
||||
Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0,
|
||||
'Usernames must have only letters, numbers, dots or '
|
||||
'underscores')])
|
||||
password = PasswordField('Password', validators=[
|
||||
Optional(), EqualTo('password2', message='Passwords must match.')])
|
||||
password2 = PasswordField('Confirm password', validators=[Optional()])
|
||||
submit = SubmitField('Submit')
|
||||
|
||||
def validate_email(self, field):
|
||||
if User.query.filter_by(email=field.data.lower()).first():
|
||||
raise ValidationError('Email already registered.')
|
||||
|
||||
def validate_username(self, field):
|
||||
if User.query.filter_by(username=field.data).first():
|
||||
raise ValidationError('Username already in use.')
|
||||
|
@ -87,7 +87,7 @@ def resend_confirmation():
|
||||
send_email(current_user.email, 'Confirm Your Account', 'auth/email/confirm',
|
||||
user=current_user, token=token)
|
||||
flash('A new confirmation email has benn sent to you by email.')
|
||||
return redirect(url_for('maind.index'))
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
|
||||
@auth.route('/reset', methods=['GET', 'POST'])
|
||||
@ -130,7 +130,15 @@ def password_reset(token):
|
||||
def profile():
|
||||
form = ChangeProfileForm()
|
||||
if form.validate_on_submit():
|
||||
flash('It\'s just a test, nothing changed.')
|
||||
flash('It is just a test, nothing changed.')
|
||||
if form.username.data:
|
||||
current_user.username = form.username.data
|
||||
db.session.add(current_user)
|
||||
if form.email.data:
|
||||
current_user.email = form.email.data
|
||||
current_user.confirmed = False
|
||||
db.session.add(current_user)
|
||||
db.session.commit()
|
||||
return redirect(url_for('auth.profile'))
|
||||
return render_template('auth/profile.html.j2', form=form,
|
||||
title='Profile')
|
||||
|
Reference in New Issue
Block a user