Push one fix idea for multiple forms

This commit is contained in:
Stephan Porada 2019-10-31 13:19:18 +01:00
parent 755f5f3137
commit 61545ed4ec
2 changed files with 19 additions and 9 deletions

View File

@ -1,9 +1,9 @@
from flask_wtf import FlaskForm
from wtforms import (PasswordField, StringField, SubmitField,
ValidationError, BooleanField)
from wtforms.validators import DataRequired, EqualTo, Length, Email
from wtforms.validators import DataRequired, EqualTo, Email
from ..models import User
import logging
class ChangePasswordForm(FlaskForm):
"""

View File

@ -45,14 +45,24 @@ def profile_change_password():
@login_required
def profile_edit_user_info():
edit_user_info_form = EditProfileForm(user=current_user)
if not edit_user_info_form.validate_on_submit():
abort(400)
current_user.email = edit_user_info_form.email.data
db.session.add(current_user._get_current_object())
db.session.commit()
flash('Your email has been updated.')
if edit_user_info_form.validate_on_submit():
current_user.email = edit_user_info_form.email.data
db.session.add(current_user._get_current_object())
db.session.commit()
flash('Your email has been updated.')
else:
logger.warning('Form: {}'.format(edit_user_info_form.errors))
return render_template('profile/index.html.j2',
change_password_form=ChangePasswordForm(),
edit_user_info_form=edit_user_info_form,
edit_user_settings_form=EditUserSettingsForm(),
title='Profile')
edit_user_info_form.email.data = current_user.email
return redirect(url_for('profile.index'))
return render_template('profile/index.html.j2',
change_password_form=ChangePasswordForm(),
edit_user_info_form=EditProfileForm(user=current_user),
edit_user_settings_form=EditUserSettingsForm(),
title='Profile')
@profile.route('/edit_user_settings', methods=['POST'])