Project

General

Profile

0001-registration-use-messages-framework-to-display-error.patch

Serghei Mihai, 11 June 2015 12:34 PM

Download (4.42 KB)

View differences:

Subject: [PATCH] registration: use messages framework to display errors
 (#7533)

 src/authentic2/registration_backend/urls.py                   |  6 ------
 src/authentic2/registration_backend/views.py                  | 10 ++++++----
 src/authentic2/templates/registration/activation_expired.html | 11 -----------
 src/authentic2/templates/registration/activation_failed.html  | 11 -----------
 4 files changed, 6 insertions(+), 32 deletions(-)
 delete mode 100644 src/authentic2/templates/registration/activation_expired.html
 delete mode 100644 src/authentic2/templates/registration/activation_failed.html
src/authentic2/registration_backend/urls.py
7 7
from .views import RegistrationView, registration_completion, DeleteView
8 8

  
9 9
urlpatterns = patterns('',
10
    url(r'^activate/expired/$',
11
        TemplateView.as_view(template_name='registration/activation_expired.html'),
12
        name='registration_activation_expired'),
13
    url(r'^activate/failed/$',
14
        TemplateView.as_view(template_name='registration/activation_failed.html'),
15
        name='registration_activation_failed'),
16 10
    url(r'^activate/(?P<registration_token>[\w:-]+)/$',
17 11
	registration_completion, name='registration_activate'),
18 12
    url(r'^register/$',
src/authentic2/registration_backend/views.py
26 26
            request.token = signing.loads(kwargs['registration_token'],
27 27
                                                max_age=settings.ACCOUNT_ACTIVATION_DAYS*3600*24)
28 28
        except signing.SignatureExpired:
29
            return redirect(request, 'registration_activation_expired')
29
            messages.warning(request, _('Your activation key is expired'))
30
            return redirect(request, 'registration_register')
30 31
        except signing.BadSignature:
31
            return redirect(request, 'registration_activation_failed')
32
            messages.warning(request, _('Activation failed'))
33
            return redirect(request, 'registration_register')
32 34
        return method(request, *args, **kwargs)
33 35
    return f
34 36

  
......
56 58

  
57 59
    def dispatch(self, request, *args, **kwargs):
58 60
        self.token = request.token
59
        self.email = request.token['email'] 
61
        self.email = request.token['email']
60 62
        self.users = User.objects.filter(email__iexact=self.email) \
61 63
            .order_by('date_joined')
62 64
        self.email_is_unique = app_settings.A2_EMAIL_IS_UNIQUE \
......
95 97
                    validators=[validators.UsernameValidator()])
96 98
            form_class = type('RegistrationForm', (form_class,), {'username': field})
97 99
        return form_class
98
    
100

  
99 101

  
100 102
    def get_form_kwargs(self, **kwargs):
101 103
        '''Initialize mail from token'''
src/authentic2/templates/registration/activation_expired.html
1
{% extends "authentic2/base-page.html" %}
2
{% load i18n %}
3

  
4
{% block title %}
5
{% trans "Account activation expired" %}
6
{% endblock %}
7

  
8
{% block content %}
9
<h2>{% trans "Account activation" %}</h2>
10
<p>{% trans "Your activation key is expired" %}</p>
11
{% endblock %}
src/authentic2/templates/registration/activation_failed.html
1
{% extends "authentic2/base-page.html" %}
2
{% load i18n %}
3

  
4
{% block title %}
5
{% trans "Account activation failed" %}
6
{% endblock %}
7

  
8
{% block content %}
9
<h2>{% trans "Account activation" %}</h2>
10
<p>{% trans "Activation failed" %}</p>
11
{% endblock %}
12
-