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.
This commit is contained in:
Benjamin Dauvergne 2015-03-26 16:10:14 +01:00
parent 5232d170ab
commit 06fe6bf97b
6 changed files with 28 additions and 7 deletions

View File

@ -12,7 +12,7 @@
<div id="content">
<div id="user-info">
{{ user.get_full_name }}
(<a href="{% url "auth_password_change" %}">{% trans "Password change" %}</a>)
(<a href="{% url "password_change" %}">{% trans "Password change" %}</a>)
</div>
<ul class="apps">

View File

@ -148,7 +148,7 @@ class ViewRestrictionMiddleware(object):
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)
@ -160,7 +160,7 @@ class ViewRestrictionMiddleware(object):
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)

View File

@ -32,6 +32,27 @@ urlpatterns = patterns('authentic2.views',
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<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[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},
@ -39,7 +60,7 @@ urlpatterns = patterns('authentic2.views',
url(r'^password/change/done/$',
auth_views.password_change_done,
name='auth_password_change_done'),
url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
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})/$',
auth_views.password_reset_confirm,
{'set_password_form': SET_PASSWORD_FORM_CLASS},
name='auth_password_reset_confirm'),

View File

@ -3,7 +3,7 @@
<div>
{% if can_change_password %}
<p><a href="{% url 'auth_password_change' %}">{% trans "Change password" %}</a></p>
<p><a href="{% url 'password_change' %}">{% trans "Change password" %}</a></p>
{% else %}
{% comment %} <p><a href="{% url 'authopenid_password_change' %}">{% trans "Set password" %}</a></p> {% endcomment %}
{% endif %}

View File

@ -12,7 +12,7 @@
<div class="login-actions">
{% if can_reset_password %}
<p>→ {% trans "Forgot password?" %} <a href="{% url 'auth_password_reset' %}">{% trans "Reset it!" %}</a></p>
<p>→ {% trans "Forgot password?" %} <a href="{% url 'password_reset' %}">{% trans "Reset it!" %}</a></p>
{% endif %}
{% if registration_authorized %}
<p>→ {% trans "Not a member?" %} <a href="{% url 'registration_register' %}?{{ request.GET.urlencode }}">{% trans "Register!" %}</a></p>

View File

@ -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 %}