From 0280ff28fedf728ce4b03d001ba67cbd93f394d8 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 26 Mar 2015 16:10:14 +0100 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(-) diff --git a/src/authentic2/manager/templates/authentic2/manager/homepage.html b/src/authentic2/manager/templates/authentic2/manager/homepage.html index b7801db..3cc775c 100644 --- a/src/authentic2/manager/templates/authentic2/manager/homepage.html +++ b/src/authentic2/manager/templates/authentic2/manager/homepage.html @@ -7,17 +7,17 @@ {% block appbar %}

{% trans "Welcome" %}

{% endblock %} {% block content %}

diff --git a/src/authentic2/middleware.py b/src/authentic2/middleware.py index 929e3f7..70345e5 100644 --- a/src/authentic2/middleware.py +++ b/src/authentic2/middleware.py @@ -129,23 +129,23 @@ class ViewRestrictionMiddleware(object): '''Check if a restriction on accessible views must be applied''' from django.db.models import Model from .models import PasswordReset user = request.user if user.is_authenticated() \ and isinstance(user, Model) \ and PasswordReset.objects.filter(user=request.user).exists(): - return 'auth_password_change' + return 'password_change' for plugin in plugins.get_plugins(): if hasattr(plugin, 'check_view_restrictions'): view = plugin.check_view_restrictions(request) if view: return view def process_view(self, request, view_func, view_args, view_kwargs): '''If current view is not the one we should be, redirect''' view = self.check_view_restrictions(request) if not view or request.resolver_match.url_name in (view, 'auth_logout'): return - if view == 'auth_password_change': + if view == 'password_change': messages.warning(request, _('You must change your password to continue')) return utils.redirect_and_come_back(request, view) diff --git a/src/authentic2/profile_urls.py b/src/authentic2/profile_urls.py index 16b751e..cb9fbd3 100644 --- a/src/authentic2/profile_urls.py +++ b/src/authentic2/profile_urls.py @@ -30,21 +30,42 @@ urlpatterns = patterns('authentic2.views', url(r'^edit/$', 'edit_profile', name='profile_edit'), url(r'^change-email/$', 'email_change', name='email-change'), url(r'^change-email/verify/$', 'email_change_verify', name='email-change-verify'), url(r'^$', 'profile', name='account_management'), url(r'^password/change/$', password_change_view, {'password_change_form': CHANGE_PASSWORD_FORM_CLASS}, + name='password_change'), + url(r'^password/change/done/$', + auth_views.password_change_done, + name='password_change_done'), + url(r'^password/reset/confirm/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', + auth_views.password_reset_confirm, + {'set_password_form': SET_PASSWORD_FORM_CLASS}, + name='password_reset_confirm'), + url(r'^password/reset/$', + auth_views.password_reset, + name='password_reset'), + url(r'^password/reset/complete/$', + auth_views.password_reset_complete, + name='password_reset_complete'), + url(r'^password/reset/done/$', + auth_views.password_reset_done, + name='password_reset_done'), + # Legacy + url(r'^password/change/$', + password_change_view, + {'password_change_form': CHANGE_PASSWORD_FORM_CLASS}, name='auth_password_change'), url(r'^password/change/done/$', auth_views.password_change_done, name='auth_password_change_done'), - url(r'^password/reset/confirm/(?P[0-9A-Za-z]+)-(?P.+)/$', + url(r'^password/reset/confirm/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', auth_views.password_reset_confirm, {'set_password_form': SET_PASSWORD_FORM_CLASS}, name='auth_password_reset_confirm'), url(r'^password/reset/$', auth_views.password_reset, name='auth_password_reset'), url(r'^password/reset/complete/$', auth_views.password_reset_complete, diff --git a/src/authentic2/templates/auth/login_password_profile.html b/src/authentic2/templates/auth/login_password_profile.html index b2dc226..f3c79aa 100644 --- a/src/authentic2/templates/auth/login_password_profile.html +++ b/src/authentic2/templates/auth/login_password_profile.html @@ -1,11 +1,11 @@ {% load i18n %} {% if can_change_password %}

{% trans "Password" %}

{% endif %}
{% if can_change_password %} -

{% trans "Change password" %}

+

{% trans "Change password" %}

{% else %} {% comment %}

{% trans "Set password" %}

{% endcomment %} {% endif %}
diff --git a/src/authentic2/templates/authentic2/login_password_form.html b/src/authentic2/templates/authentic2/login_password_form.html index 626a840..0262f41 100644 --- a/src/authentic2/templates/authentic2/login_password_form.html +++ b/src/authentic2/templates/authentic2/login_password_form.html @@ -7,16 +7,16 @@ {% if cancel %} {% endif %} {% addtoblock "js-endpage" %}{% endaddtoblock %} diff --git a/src/authentic2/templates/registration/password_reset_email.html b/src/authentic2/templates/registration/password_reset_email.html index f5f09ec..ad81d14 100644 --- a/src/authentic2/templates/registration/password_reset_email.html +++ b/src/authentic2/templates/registration/password_reset_email.html @@ -1,5 +1,5 @@ {% load i18n %} {% blocktrans %}Reset password at {{ site_name }}{% endblocktrans %}: {% block reset_link %} -{{ protocol }}://{{ domain }}{% url 'auth_password_reset_confirm' uidb36=uid token=token %} +{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} {% endblock %} -- 1.9.1