From 60f1cb7573eabd4af5ffd5bd543075bc2f01bccf Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Mon, 4 Nov 2019 09:52:55 +0100 Subject: [PATCH] Revert to view per formular in user settings --- app/profile/views.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/profile/views.py b/app/profile/views.py index 69b32ae6..9cc60cc2 100644 --- a/app/profile/views.py +++ b/app/profile/views.py @@ -28,17 +28,26 @@ def index(): @profile.route('/change_password', methods=['POST']) @login_required def profile_change_password(): + edit_user_info_form = EditProfileForm(user=current_user) change_password_form = ChangePasswordForm() - if not change_password_form.validate_on_submit(): - abort(400) - if current_user.verify_password(change_password_form.old_password.data): - current_user.password = change_password_form.new_password.data - db.session.add(current_user) - db.session.commit() - flash('Your password has been updated.') + if change_password_form.validate_on_submit(): + if current_user.verify_password(change_password_form.old_password.data): + current_user.password = change_password_form.new_password.data + db.session.add(current_user) + db.session.commit() + 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: 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']) @@ -75,6 +84,10 @@ def profile_edit_user_settings(): logger.warning('Form data: {}'.format(current_user.is_dark)) db.session.add(current_user) 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'))