Ticket #16919: setpasswordform_withtests.diff

File setpasswordform_withtests.diff, 2.4 KB (added by Ethan Jucovy, 13 years ago)
  • django/contrib/auth/views.py

     
    208208                form.save()
    209209                return HttpResponseRedirect(post_reset_redirect)
    210210        else:
    211             form = set_password_form(None)
     211            form = set_password_form(user)
    212212    else:
    213213        validlink = False
    214214        form = None
  • django/contrib/auth/tests/views.py

     
    180180        self.assertEqual(response.status_code, 200)
    181181        self.assertContainsEscaped(response, SetPasswordForm.error_messages['password_mismatch'])
    182182
     183    def test_confirm_display_user_from_form(self):
     184        url, path = self._test_confirm_start()
     185        response = self.client.get(path)
    183186
     187        # The ``password_reset_confirm`` view should stash the user object
     188        # on the ``SetPasswordForm`` object that it creates, even on GET requests.
     189        # For this test suite, we render ``{{ form.user }}`` in the template
     190        # ``registration/password_reset_confirm.html`` so that we can test this.
     191        # See #16919.
     192        username = User.objects.get(email='staffmember@example.com').username
     193        self.assertTrue("Hello, %s." % username in response.content)
     194
     195        # However, the view should NOT stash any user object on a form if the
     196        # password reset link was invalid.
     197        response = self.client.get('/reset/zzzzzzzzzzzzz-1-1/')
     198        self.assertTrue("Hello, ." in response.content)
     199
    184200class ChangePasswordTest(AuthViewsTestCase):
    185201
    186202    def fail_login(self, password='password'):
  • django/contrib/auth/tests/templates/registration/password_reset_confirm.html

     
     1Hello, {{ form.user }}.
     2
    13{% if validlink %}
    24Please enter your new password: {{ form }}
    35{% else %}
     
    24The password reset link was invalid
    3 {% endif %}
    4  No newline at end of file
     5{% endif %}
Back to Top