Projet

Général

Profil

0001-accounts-use-Django-naming-for-password-related-view.patch

Benjamin Dauvergne, 30 mars 2015 11:11

Télécharger (8,16 ko)

Voir les différences:

Subject: [PATCH] accounts: use Django naming for password related views, keep
 previous name for retrocompatibility with already deployed themes (#6851)

Django 1.7 now use accounting view names directly in its code, they also
changed the signature of the password_change_done view regexp (it
expects a uidb64 argument instead of uidb36). To minimize difference
with expected view names but to also keep retrocompatibility view names
were renamed with the Django names and old declarations were kept but
declared after the official ones such that they will never match a
request but they can still be used for reversing view names.
 .../templates/authentic2/manager/homepage.html     |  2 +-
 src/authentic2/middleware.py                       |  4 ++--
 src/authentic2/profile_urls.py                     | 23 +++++++++++++++++++++-
 .../templates/auth/login_password_profile.html     |  2 +-
 .../templates/authentic2/login_password_form.html  |  2 +-
 .../registration/password_reset_email.html         |  2 +-
 6 files changed, 28 insertions(+), 7 deletions(-)
src/authentic2/manager/templates/authentic2/manager/homepage.html
7 7
{% block appbar %}
8 8
   <h2>{% trans "Welcome" %}</h2>
9 9
{% endblock %}
10 10

  
11 11
{% block content %}
12 12
  <div id="content">
13 13
     <div id="user-info">
14 14
       {{ user.get_full_name }}
15
       (<a href="{% url "auth_password_change" %}">{% trans "Password change" %}</a>)
15
       (<a href="{% url "password_change" %}">{% trans "Password change" %}</a>)
16 16
     </div>
17 17

  
18 18
      <ul class="apps">
19 19
        <li id="users"><a href="{% url "a2-manager-users" %}">{% trans "User management" %}</a></li>
20 20
        <li id="roles"><a href="{% url "a2-manager-roles" %}">{% trans "Role management" %}</a></li>
21 21
      </ul>
22 22
      <br style="clear: both;"/>
23 23
  </div>
src/authentic2/middleware.py
129 129
        '''Check if a restriction on accessible views must be applied'''
130 130
        from django.db.models import Model
131 131
        from .models import PasswordReset
132 132

  
133 133
        user = request.user
134 134
        if user.is_authenticated() \
135 135
                and isinstance(user, Model) \
136 136
                and PasswordReset.objects.filter(user=request.user).exists():
137
            return 'auth_password_change'
137
            return 'password_change'
138 138
        for plugin in plugins.get_plugins():
139 139
            if hasattr(plugin, 'check_view_restrictions'):
140 140
                view = plugin.check_view_restrictions(request)
141 141
                if view:
142 142
                    return view
143 143

  
144 144
    def process_view(self, request, view_func, view_args, view_kwargs):
145 145
        '''If current view is not the one we should be, redirect'''
146 146
        view = self.check_view_restrictions(request)
147 147
        if not view or request.resolver_match.url_name in (view, 'auth_logout'):
148 148
            return
149
        if view == 'auth_password_change':
149
        if view == 'password_change':
150 150
            messages.warning(request, _('You must change your password to continue'))
151 151
        return utils.redirect_and_come_back(request, view)
src/authentic2/profile_urls.py
30 30
    url(r'^edit/$', 'edit_profile', name='profile_edit'),
31 31
    url(r'^change-email/$', 'email_change', name='email-change'),
32 32
    url(r'^change-email/verify/$', 'email_change_verify',
33 33
        name='email-change-verify'),
34 34
    url(r'^$', 'profile', name='account_management'),
35 35
    url(r'^password/change/$',
36 36
        password_change_view,
37 37
        {'password_change_form': CHANGE_PASSWORD_FORM_CLASS},
38
        name='password_change'),
39
    url(r'^password/change/done/$',
40
        auth_views.password_change_done,
41
        name='password_change_done'),
42
    url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
43
        auth_views.password_reset_confirm,
44
        {'set_password_form': SET_PASSWORD_FORM_CLASS},
45
        name='password_reset_confirm'),
46
    url(r'^password/reset/$',
47
        auth_views.password_reset,
48
        name='password_reset'),
49
    url(r'^password/reset/complete/$',
50
        auth_views.password_reset_complete,
51
        name='password_reset_complete'),
52
    url(r'^password/reset/done/$',
53
        auth_views.password_reset_done,
54
        name='password_reset_done'),
55
    # Legacy 
56
    url(r'^password/change/$',
57
        password_change_view,
58
        {'password_change_form': CHANGE_PASSWORD_FORM_CLASS},
38 59
        name='auth_password_change'),
39 60
    url(r'^password/change/done/$',
40 61
        auth_views.password_change_done,
41 62
        name='auth_password_change_done'),
42
    url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
63
    url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
43 64
        auth_views.password_reset_confirm,
44 65
        {'set_password_form': SET_PASSWORD_FORM_CLASS},
45 66
        name='auth_password_reset_confirm'),
46 67
    url(r'^password/reset/$',
47 68
        auth_views.password_reset,
48 69
        name='auth_password_reset'),
49 70
    url(r'^password/reset/complete/$',
50 71
        auth_views.password_reset_complete,
src/authentic2/templates/auth/login_password_profile.html
1 1
{% load i18n %}
2 2
{% if can_change_password %}<h4>{% trans "Password" %}</h4>{% endif %}
3 3

  
4 4
<div>
5 5
{% if can_change_password %}
6
 <p><a href="{% url 'auth_password_change' %}">{% trans "Change password" %}</a></p>
6
 <p><a href="{% url 'password_change' %}">{% trans "Change password" %}</a></p>
7 7
{% else %}
8 8
{% comment %} <p><a href="{% url 'authopenid_password_change' %}">{% trans "Set password" %}</a></p> {% endcomment %}
9 9
{% endif %}
10 10
</div>
11 11

  
src/authentic2/templates/authentic2/login_password_form.html
7 7
{% if cancel %}
8 8
<input type="submit" name="cancel" value="{% trans 'Cancel' %}"/>
9 9
{% endif %}
10 10
</form>
11 11
</div>
12 12

  
13 13
<div class="login-actions">
14 14
{% if can_reset_password %}
15
  <p>→ {% trans "Forgot password?" %} <a href="{% url 'auth_password_reset' %}">{% trans "Reset it!" %}</a></p>
15
  <p>→ {% trans "Forgot password?" %} <a href="{% url 'password_reset' %}">{% trans "Reset it!" %}</a></p>
16 16
{% endif %}
17 17
{% if registration_authorized %}
18 18
  <p>→ {% trans "Not a member?" %} <a href="{% url 'registration_register' %}?{{ request.GET.urlencode }}">{% trans "Register!" %}</a></p>
19 19
{% endif %}
20 20
</div>
21 21

  
22 22
{% addtoblock "js-endpage" %}<script type="text/javascript" src="{% static "authentic2/js/js_seconds_until.js" %}"></script>{% endaddtoblock %}
src/authentic2/templates/registration/password_reset_email.html
1 1
{% load i18n %}
2 2
{% blocktrans %}Reset password at {{ site_name }}{% endblocktrans %}:
3 3
{% block reset_link %}
4
{{ protocol }}://{{ domain }}{% url 'auth_password_reset_confirm' uidb36=uid token=token %}
4
{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}
5 5
{% endblock %}
6
-