Projet

Général

Profil

0006-next_url-param-propagated-from-service-provider-to-r.patch

Serghei Mihai (congés, retour 15/05), 16 septembre 2014 14:19

Télécharger (5,04 ko)

Voir les différences:

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(-)
authentic2/registration_backend/views.py
29 29
    template_name = 'registration/registration_form.html'
30 30

  
31 31
    def form_valid(self, form):
32
        activation_key = signing.dumps(form.cleaned_data)
32
        data = form.cleaned_data
33
        data.update({'next_url': self.request.GET.get('next_url')})
34
        activation_key = signing.dumps(data)
33 35
        ctx_dict = {'activation_key': activation_key,
34 36
                    'expiration_days': EXPIRATION,
35 37
                    'site': self.request.get_host()}
......
53 55
    template_name = 'registration/activate.html'
54 56

  
55 57
    def get(self, request, *args, **kwargs):
56
        context = {}
58
        context = {'activated': False, 'next_url': None}
57 59
        try:
58
            user = authenticate(**self.register(kwargs['activation_key']))
60
            registration_kwargs = self.register(kwargs['activation_key'])
61
            next_url = registration_kwargs.pop('next_url')
62
            user = authenticate(**registration_kwargs)
59 63
            login(request, user)
60
            messages.info(request, _('Your account has been successfully activated. You are now logged in.'))
61
            return redirect('auth_homepage')
64
            context['next_url'] = next_url
65
            context['activated'] = True
62 66
        except signing.SignatureExpired:
63 67
            context['expired'] = True
64 68
        except IntegrityError:
......
69 73
        User = compat.get_user_model()
70 74
        registration_fields = signing.loads(registration_token,
71 75
                                            max_age=EXPIRATION * 3600 * 24)
76

  
72 77
        user_fields = {}
73 78
        for field in compat.get_registration_fields():
74 79
            # save User model fields
......
99 104
                groups.append(group)
100 105
            new_user.groups = groups
101 106
        return {'username': registration_fields['username'],
102
                'password': registration_fields['password1']}
107
                'password': registration_fields['password1'],
108
                'next_url': registration_fields['next_url']}
103 109

  
104 110
class DeleteView(TemplateView):
105 111
    def get(self, request, *args, **kwargs):
authentic2/templates/auth/login_form.html
15 15
  <p>→ {% trans "Forgot password?" %} <a href="{% url 'auth_password_reset' %}">{% trans "Reset it!" %}</a></p>
16 16
{% endif %}
17 17
{% if registration_authorized %}
18
  <p>→ {% trans "Not a member?" %} <a href="{% url 'registration_register' %}">{% trans "Register!" %}</a></p>
18
  <p>→ {% trans "Not a member?" %} <a href="{% url 'registration_register' %}?{{ request.GET.urlencode }}">{% trans "Register!" %}</a></p>
19 19
{% endif %}
20 20
</div>
authentic2/templates/registration/activate.html
7 7

  
8 8
{% block content %}
9 9

  
10
{% if account %}
11

  
12
<p>{% trans "Account successfully activated" %}</p>
13

  
14
<p><a href="{% url 'auth_login' %}">{% trans "Log in" %}</a></p>
10
{% if activated %}
11
<p>{% trans "Account successfully activated. You are now logged in." %}</p>
15 12

  
13
{% if next_url %}
14
<a href="{{ next_url }}">
16 15
{% else %}
16
<a href="{% url 'auth_homepage' %}">
17
{% endif %}
18
{% trans "Continue" %}</a>
17 19

  
20
{% else %}
18 21
<p>{% trans "Account activation failed" %}</p>
22

  
19 23
{% if expired %}
20 24
<p>{% trans "Your activation key is expired" %}</p>
21 25
{% endif %}
26

  
22 27
{% if existing_user %}
23 28
<p>{% trans "A user with that username already exists." %}</p>
24 29
{% endif %}
authentic2/templates/registration/registration_form.html
15 15

  
16 16
<h2>{% trans "Registration" %}</h2>
17 17

  
18
<form method="post" action=".">
18
<form method="post">
19 19
  {% csrf_token %}
20 20
  {{ form.as_p }}
21 21

  
22
-