Revert to view per formular in user settings

This commit is contained in:
Stephan Porada 2019-11-04 09:52:55 +01:00
parent 799101d380
commit 60f1cb7573

View File

@ -28,17 +28,26 @@ def index():
@profile.route('/change_password', methods=['POST']) @profile.route('/change_password', methods=['POST'])
@login_required @login_required
def profile_change_password(): def profile_change_password():
edit_user_info_form = EditProfileForm(user=current_user)
change_password_form = ChangePasswordForm() change_password_form = ChangePasswordForm()
if not change_password_form.validate_on_submit(): if change_password_form.validate_on_submit():
abort(400) if current_user.verify_password(change_password_form.old_password.data):
if current_user.verify_password(change_password_form.old_password.data): current_user.password = change_password_form.new_password.data
current_user.password = change_password_form.new_password.data db.session.add(current_user)
db.session.add(current_user) db.session.commit()
db.session.commit() flash('Your password has been updated.')
flash('Your password has been updated.') return render_template('profile/index.html.j2',
change_password_form=change_password_form,
edit_user_info_form=edit_user_info_form,
edit_user_settings_form=EditUserSettingsForm(),
title='Profile')
else: else:
flash('Invalid password.') flash('Invalid password.')
return redirect(url_for('profile.index')) return render_template('profile/index.html.j2',
change_password_form=change_password_form,
edit_user_info_form=edit_user_info_form,
edit_user_settings_form=EditUserSettingsForm(),
title='Profile')
@profile.route('/edit_user_info', methods=['POST']) @profile.route('/edit_user_info', methods=['POST'])
@ -75,6 +84,10 @@ def profile_edit_user_settings():
logger.warning('Form data: {}'.format(current_user.is_dark)) logger.warning('Form data: {}'.format(current_user.is_dark))
db.session.add(current_user) db.session.add(current_user)
db.session.commit() db.session.commit()
if current_user.is_dark is True:
flash('Dark mode has been activated!')
else:
flash('Dark mode has been deactivated!')
return redirect(url_for('profile.index')) return redirect(url_for('profile.index'))