From 3d78776cf26f4eb07f542c6e40991c59c2535e53 Mon Sep 17 00:00:00 2001 From: Serghei MIHAI Date: Thu, 11 Sep 2014 15:41:20 +0200 Subject: [PATCH 6/6] next_url param propagated from service provider to registration form. Provider's link displayed on account activation. Closes #2803 --- authentic2/registration_backend/views.py | 18 ++++++++++++------ authentic2/templates/auth/login_form.html | 2 +- authentic2/templates/registration/activate.html | 15 ++++++++++----- .../templates/registration/registration_form.html | 2 +- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/authentic2/registration_backend/views.py b/authentic2/registration_backend/views.py index d7e3eeb..a3c1eb4 100644 --- a/authentic2/registration_backend/views.py +++ b/authentic2/registration_backend/views.py @@ -29,7 +29,9 @@ class RegistrationView(FormView): template_name = 'registration/registration_form.html' def form_valid(self, form): - activation_key = signing.dumps(form.cleaned_data) + data = form.cleaned_data + data.update({'next_url': self.request.GET.get('next_url')}) + activation_key = signing.dumps(data) ctx_dict = {'activation_key': activation_key, 'expiration_days': EXPIRATION, 'site': self.request.get_host()} @@ -53,12 +55,14 @@ class ActivationView(TemplateView): template_name = 'registration/activate.html' def get(self, request, *args, **kwargs): - context = {} + context = {'activated': False, 'next_url': None} try: - user = authenticate(**self.register(kwargs['activation_key'])) + registration_kwargs = self.register(kwargs['activation_key']) + next_url = registration_kwargs.pop('next_url') + user = authenticate(**registration_kwargs) login(request, user) - messages.info(request, _('Your account has been successfully activated. You are now logged in.')) - return redirect('auth_homepage') + context['next_url'] = next_url + context['activated'] = True except signing.SignatureExpired: context['expired'] = True except IntegrityError: @@ -69,6 +73,7 @@ class ActivationView(TemplateView): User = compat.get_user_model() registration_fields = signing.loads(registration_token, max_age=EXPIRATION * 3600 * 24) + user_fields = {} for field in compat.get_registration_fields(): # save User model fields @@ -99,7 +104,8 @@ class ActivationView(TemplateView): groups.append(group) new_user.groups = groups return {'username': registration_fields['username'], - 'password': registration_fields['password1']} + 'password': registration_fields['password1'], + 'next_url': registration_fields['next_url']} class DeleteView(TemplateView): def get(self, request, *args, **kwargs): diff --git a/authentic2/templates/auth/login_form.html b/authentic2/templates/auth/login_form.html index c47bc0e..c5f8fb7 100644 --- a/authentic2/templates/auth/login_form.html +++ b/authentic2/templates/auth/login_form.html @@ -15,6 +15,6 @@

→ {% trans "Forgot password?" %} {% trans "Reset it!" %}

{% endif %} {% if registration_authorized %} -

→ {% trans "Not a member?" %} {% trans "Register!" %}

+

→ {% trans "Not a member?" %} {% trans "Register!" %}

{% endif %} diff --git a/authentic2/templates/registration/activate.html b/authentic2/templates/registration/activate.html index f147cc5..ba4715e 100644 --- a/authentic2/templates/registration/activate.html +++ b/authentic2/templates/registration/activate.html @@ -7,18 +7,23 @@ {% block content %} -{% if account %} - -

{% trans "Account successfully activated" %}

- -

{% trans "Log in" %}

+{% if activated %} +

{% trans "Account successfully activated. You are now logged in." %}

+{% if next_url %} + {% else %} + +{% endif %} +{% trans "Continue" %} +{% else %}

{% trans "Account activation failed" %}

+ {% if expired %}

{% trans "Your activation key is expired" %}

{% endif %} + {% if existing_user %}

{% trans "A user with that username already exists." %}

{% endif %} diff --git a/authentic2/templates/registration/registration_form.html b/authentic2/templates/registration/registration_form.html index f0ea73c..842a1dc 100644 --- a/authentic2/templates/registration/registration_form.html +++ b/authentic2/templates/registration/registration_form.html @@ -15,7 +15,7 @@

{% trans "Registration" %}

-
+ {% csrf_token %} {{ form.as_p }} -- 2.1.0