Projet

Général

Profil

0002-views-thread-next-through-pre-registration-views-fix.patch

Benjamin Dauvergne, 07 janvier 2019 12:45

Télécharger (3,32 ko)

Voir les différences:

Subject: [PATCH 2/2] views: thread ?next= through pre-registration views
 (fixes #29242)

 src/authentic2/registration_backend/views.py               | 4 +++-
 .../templates/registration/registration_complete.html      | 3 +--
 tests/test_registration.py                                 | 7 +++++++
 3 files changed, 11 insertions(+), 3 deletions(-)
src/authentic2/registration_backend/views.py
88 88
        utils.send_registration_mail(self.request, email, next_url=self.next_url,
89 89
                                     ou=self.ou, **self.token)
90 90
        self.request.session['registered_email'] = email
91
        return redirect(self.request, 'registration_complete')
91
        return redirect(self.request, 'registration_complete', params={REDIRECT_FIELD_NAME: self.next_url})
92 92

  
93 93
    def get_context_data(self, **kwargs):
94 94
        context = super(BaseRegistrationView, self).get_context_data(**kwargs)
......
406 406
    template_name = 'registration/registration_complete.html'
407 407

  
408 408
    def get_context_data(self, **kwargs):
409
        kwargs['next_url'] = utils.select_next_url(self.request, settings.LOGIN_REDIRECT_URL)
409 410
        return super(RegistrationCompleteView, self).get_context_data(
410 411
            account_activation_days=settings.ACCOUNT_ACTIVATION_DAYS,
411 412
            **kwargs)
412 413

  
414

  
413 415
registration_complete = RegistrationCompleteView.as_view()
src/authentic2/templates/registration/registration_complete.html
6 6
{% endblock %}
7 7

  
8 8
{% block content %}
9
  {% url "auth_homepage" as homepage_url %}
10 9
  {% blocktrans with email=request.session.registered_email %}
11 10
    <p>An email was sent to {{ email }}.</p>
12 11
  {% endblocktrans %}
......
21 20
    email will be valid during 24 hours.</p>
22 21
  {% endblocktrans %}
23 22
  {% endif %}
24
  <p><a href="{{ homepage_url }}">{% trans "Back" %}</a></p>
23
  <p><a href="{{ next_url }}">{% trans "Back" %}</a></p>
25 24
{% endblock %}
tests/test_registration.py
28 28
    response = response.form.submit()
29 29

  
30 30
    assert urlparse(response['Location']).path == reverse('registration_complete')
31
    if not good_next_url:
32
        assert not urlparse(response['Location']).query
31 33

  
32 34
    response = response.follow()
35
    if good_next_url:
36
        assert response.pyquery('a[href="%s"]' % next_url)
37
    else:
38
        assert response.pyquery('a[href="/"]')
39

  
33 40
    assert '2 days' in response.content
34 41
    assert 'testbot@entrouvert.com' in response.content
35 42
    assert len(mailoutbox) == 1
36
-