Ticket #26960: 26960.diff

File 26960.diff, 3.5 KB (added by Jordi, 8 years ago)
  • django/contrib/auth/views.py

    diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
    index 12bb666..ef5c9d8 100644
    a b class PasswordResetConfirmView(PasswordContextMixin, FormView):  
    406406    template_name = 'registration/password_reset_confirm.html'
    407407    title = _('Enter new password')
    408408    token_generator = default_token_generator
     409    post_reset_login = False
    409410
    410411    @method_decorator(sensitive_post_parameters())
    411412    @method_decorator(never_cache)
    class PasswordResetConfirmView(PasswordContextMixin, FormView):  
    429430        return kwargs
    430431
    431432    def form_valid(self, form):
    432         form.save()
     433        user = form.save()
     434        if self.post_reset_login:
     435            auth_login(self.request, user)
    433436        return super(PasswordResetConfirmView, self).form_valid(form)
    434437
    435438    def get_context_data(self, **kwargs):
  • docs/topics/auth/default.txt

    diff --git a/docs/topics/auth/default.txt b/docs/topics/auth/default.txt
    index 5fd8ab4..9990bfb 100644
    a b implementation details see :ref:`using-the-views`.  
    14751475      will default to ``default_token_generator``, it's an instance of
    14761476      ``django.contrib.auth.tokens.PasswordResetTokenGenerator``.
    14771477
    1478     * ``form_class``: Form that will be used to set the password. Defaults to
     1478    * ``post_reset_login``: Boolean, if set to True the user is going to be
     1479      automatically authenticated after the password has been successfully reset.
     1480      Set to False by default.
     1481
     1482    * ``form_class``: Form that will be used to set the password. Defaults to
    14791483      :class:`~django.contrib.auth.forms.SetPasswordForm`.
    14801484
    14811485    * ``success_url``: URL to redirect after the password reset done. Defaults
  • tests/auth_tests/test_views.py

    diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py
    index 32c51e4..f81452b 100644
    a b class PasswordResetTest(AuthViewsTestCase):  
    306306        self.assertEqual(response.status_code, 302)
    307307        self.assertURLEqual(response.url, '/password_reset/')
    308308
     309    def test_confirm_login_post_reset(self):
     310        url, path = self._test_confirm_start()
     311        path = path.replace('/reset/', '/reset/post_reset_login/')
     312        response = self.client.post(path, {'new_password1': 'anewpassword', 'new_password2': 'anewpassword'})
     313        self.assertEqual(response.status_code, 302)
     314        self.assertURLEqual(response.url, '/reset/done/')
     315        self.assertIn(SESSION_KEY, self.client.session)
     316
    309317    def test_confirm_display_user_from_form(self):
    310318        url, path = self._test_confirm_start()
    311319        response = self.client.get(path)
  • tests/auth_tests/urls.py

    diff --git a/tests/auth_tests/urls.py b/tests/auth_tests/urls.py
    index 6a7574b..e8174fb 100644
    a b urlpatterns = auth_urlpatterns + [  
    8585        views.PasswordResetConfirmView.as_view(success_url='/custom/')),
    8686    url(r'^reset/custom/named/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
    8787        views.PasswordResetConfirmView.as_view(success_url=reverse_lazy('password_reset'))),
     88    url(r'^reset/post_reset_login/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
     89        views.PasswordResetConfirmView.as_view(post_reset_login=True)),
    8890    url(r'^password_change/custom/$',
    8991        views.PasswordChangeView.as_view(success_url='/custom/')),
    9092    url(r'^password_change/custom/named/$',
Back to Top