diff --git a/flask_security/forms.py b/flask_security/forms.py index 48f7b82..3d9c7e6 100644 --- a/flask_security/forms.py +++ b/flask_security/forms.py @@ -200,7 +200,7 @@ class ResetPasswordForm(Form, NewPasswordFormMixin, PasswordConfirmFormMixin): submit = SubmitField("Reset Password") -class ChangePasswordForm(Form, NextFormMixin, PasswordFormMixin): +class ChangePasswordForm(Form, PasswordFormMixin): """The default change password form""" new_password = PasswordField("New Password", diff --git a/flask_security/templates/security/change_password.html b/flask_security/templates/security/change_password.html index 02701c4..8ee3eb7 100644 --- a/flask_security/templates/security/change_password.html +++ b/flask_security/templates/security/change_password.html @@ -6,7 +6,6 @@ {{ render_field_with_errors(change_password_form.password) }} {{ render_field_with_errors(change_password_form.new_password) }} {{ render_field_with_errors(change_password_form.new_password_confirm) }} - {{ render_field(change_password_form.next) }} {{ render_field(change_password_form.submit) }} diff --git a/flask_security/views.py b/flask_security/views.py index 587a686..dfc87fd 100644 --- a/flask_security/views.py +++ b/flask_security/views.py @@ -296,6 +296,8 @@ def change_password(): change_user_password(current_user, form.new_password.data) if request.json is None: do_flash(*get_message('PASSWORD_CHANGE')) + return redirect(get_url(_security.post_change_view) or + get_url(_security.post_login_view)) if request.json: return _render_json(form) diff --git a/tests/configured_tests.py b/tests/configured_tests.py index af248d7..67d88c4 100644 --- a/tests/configured_tests.py +++ b/tests/configured_tests.py @@ -321,8 +321,8 @@ class ExpiredResetPasswordTest(SecurityTest): class ChangePasswordTest(SecurityTest): AUTH_CONFIG = { + 'SECURITY_RECOVERABLE': True, 'SECURITY_CHANGEABLE': True, - 'SECURITY_POST_CHANGE_VIEW': '/', } def test_change_password(self): @@ -362,12 +362,37 @@ class ChangePasswordTest(SecurityTest): def test_change_password_success(self): self.authenticate() - r = self.client.post('/change', data={ - 'password': 'password', - 'new_password': 'newpassword', - 'new_password_confirm': 'newpassword' - }, follow_redirects=True) + with self.app.extensions['mail'].record_messages() as outbox: + r = self.client.post('/change', data={ + 'password': 'password', + 'new_password': 'newpassword', + 'new_password_confirm': 'newpassword' + }, follow_redirects=True) + self.assertIn('You successfully changed your password', r.data) + self.assertIn('Home Page', r.data) + + self.assertEqual(len(outbox), 1) + self.assertIn("Your password has been changed", outbox[0].html) + self.assertIn("/reset", outbox[0].html) + + +class ChangePasswordPostViewTest(SecurityTest): + + AUTH_CONFIG = { + 'SECURITY_CHANGEABLE': True, + 'SECURITY_POST_CHANGE_VIEW': '/profile', + } + + def test_change_password_success(self): + self.authenticate() + r = self.client.post('/change', data={ + 'password': 'password', + 'new_password': 'newpassword', + 'new_password_confirm': 'newpassword' + }, follow_redirects=True) + + self.assertIn('Profile Page', r.data) class TrackableTests(SecurityTest):