mirror of
https://github.com/wassname/flask-security.git
synced 2026-08-08 11:19:18 +08:00
Fix and test redir to configurable view post change
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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) }}
|
||||
</form>
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user