From 2277d192f5830d817025b148d650d080641ed5fd Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 20 Dec 2018 10:18:20 +0100 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(-) diff --git a/src/authentic2/registration_backend/views.py b/src/authentic2/registration_backend/views.py index 3338dbc2..b99ef7f3 100644 --- a/src/authentic2/registration_backend/views.py +++ b/src/authentic2/registration_backend/views.py @@ -88,7 +88,7 @@ class BaseRegistrationView(FormView): utils.send_registration_mail(self.request, email, next_url=self.next_url, ou=self.ou, **self.token) self.request.session['registered_email'] = email - return redirect(self.request, 'registration_complete') + return redirect(self.request, 'registration_complete', params={REDIRECT_FIELD_NAME: self.next_url}) def get_context_data(self, **kwargs): context = super(BaseRegistrationView, self).get_context_data(**kwargs) @@ -406,8 +406,10 @@ class RegistrationCompleteView(TemplateView): template_name = 'registration/registration_complete.html' def get_context_data(self, **kwargs): + kwargs['next_url'] = utils.select_next_url(self.request, settings.LOGIN_REDIRECT_URL) return super(RegistrationCompleteView, self).get_context_data( account_activation_days=settings.ACCOUNT_ACTIVATION_DAYS, **kwargs) + registration_complete = RegistrationCompleteView.as_view() diff --git a/src/authentic2/templates/registration/registration_complete.html b/src/authentic2/templates/registration/registration_complete.html index 7eca7a21..cb9ca8e6 100644 --- a/src/authentic2/templates/registration/registration_complete.html +++ b/src/authentic2/templates/registration/registration_complete.html @@ -6,7 +6,6 @@ {% endblock %} {% block content %} - {% url "auth_homepage" as homepage_url %} {% blocktrans with email=request.session.registered_email %}

An email was sent to {{ email }}.

{% endblocktrans %} @@ -21,5 +20,5 @@ email will be valid during 24 hours.

{% endblocktrans %} {% endif %} -

{% trans "Back" %}

+

{% trans "Back" %}

{% endblock %} diff --git a/tests/test_registration.py b/tests/test_registration.py index 0e744d89..a6a09cd5 100644 --- a/tests/test_registration.py +++ b/tests/test_registration.py @@ -28,8 +28,15 @@ def test_registration(app, db, settings, mailoutbox, external_redirect): response = response.form.submit() assert urlparse(response['Location']).path == reverse('registration_complete') + if not good_next_url: + assert not urlparse(response['Location']).query response = response.follow() + if good_next_url: + assert response.pyquery('a[href="%s"]' % next_url) + else: + assert response.pyquery('a[href="/"]') + assert '2 days' in response.content assert 'testbot@entrouvert.com' in response.content assert len(mailoutbox) == 1 -- 2.18.0