diff --git a/django/contrib/admin/templates/registration/password_change_done.html b/django/contrib/admin/templates/registration/password_change_done.html index 1c928a0d4db..3e557ebef30 100644 --- a/django/contrib/admin/templates/registration/password_change_done.html +++ b/django/contrib/admin/templates/registration/password_change_done.html @@ -8,12 +8,8 @@ {% endblock %} -{% block title %}{% trans 'Password change successful' %}{% endblock %} - +{% block title %}{{ title }}{% endblock %} +{% block content_title %}

{{ title }}

{% endblock %} {% block content %} - -

{% trans 'Password change successful' %}

-

{% trans 'Your password was changed.' %}

- {% endblock %} diff --git a/django/contrib/admin/templates/registration/password_change_form.html b/django/contrib/admin/templates/registration/password_change_form.html index f7316a739f8..921df0ac723 100644 --- a/django/contrib/admin/templates/registration/password_change_form.html +++ b/django/contrib/admin/templates/registration/password_change_form.html @@ -9,7 +9,8 @@ {% endblock %} -{% block title %}{% trans 'Password change' %}{% endblock %} +{% block title %}{{ title }}{% endblock %} +{% block content_title %}

{{ title }}

{% endblock %} {% block content %}
@@ -21,7 +22,6 @@

{% endif %} -

{% trans 'Password change' %}

{% trans "Please enter your old password, for security's sake, and then enter your new password twice so we can verify you typed it in correctly." %}

diff --git a/django/contrib/admin/templates/registration/password_reset_complete.html b/django/contrib/admin/templates/registration/password_reset_complete.html index d97f338197d..19f87a5b76b 100644 --- a/django/contrib/admin/templates/registration/password_reset_complete.html +++ b/django/contrib/admin/templates/registration/password_reset_complete.html @@ -8,12 +8,11 @@
{% endblock %} -{% block title %}{% trans 'Password reset complete' %}{% endblock %} +{% block title %}{{ title }}{% endblock %} +{% block content_title %}

{{ title }}

{% endblock %} {% block content %} -

{% trans 'Password reset complete' %}

-

{% trans "Your password has been set. You may go ahead and log in now." %}

{% trans 'Log in' %}

diff --git a/django/contrib/admin/templates/registration/password_reset_confirm.html b/django/contrib/admin/templates/registration/password_reset_confirm.html index 81020b929f9..bd24806d46c 100644 --- a/django/contrib/admin/templates/registration/password_reset_confirm.html +++ b/django/contrib/admin/templates/registration/password_reset_confirm.html @@ -8,14 +8,12 @@ {% endblock %} -{% block title %}{% trans 'Password reset' %}{% endblock %} - +{% block title %}{{ title }}{% endblock %} +{% block content_title %}

{{ title }}

{% endblock %} {% block content %} {% if validlink %} -

{% trans 'Enter new password' %}

-

{% trans "Please enter your new password twice so we can verify you typed it in correctly." %}

{% csrf_token %} @@ -28,8 +26,6 @@ {% else %} -

{% trans 'Password reset unsuccessful' %}

-

{% trans "The password reset link was invalid, possibly because it has already been used. Please request a new password reset." %}

{% endif %} diff --git a/django/contrib/admin/templates/registration/password_reset_done.html b/django/contrib/admin/templates/registration/password_reset_done.html index 98471041b56..d157306a910 100644 --- a/django/contrib/admin/templates/registration/password_reset_done.html +++ b/django/contrib/admin/templates/registration/password_reset_done.html @@ -8,12 +8,10 @@ {% endblock %} -{% block title %}{% trans 'Password reset successful' %}{% endblock %} - +{% block title %}{{ title }}{% endblock %} +{% block content_title %}

{{ title }}

{% endblock %} {% block content %} -

{% trans 'Password reset successful' %}

-

{% trans "We've emailed you instructions for setting your password. You should be receiving them shortly." %}

{% trans "If you don't receive an email, please make sure you've entered the address you registered with, and check your spam folder." %}

diff --git a/django/contrib/admin/templates/registration/password_reset_form.html b/django/contrib/admin/templates/registration/password_reset_form.html index c9998a1a3b3..dc05cd02456 100644 --- a/django/contrib/admin/templates/registration/password_reset_form.html +++ b/django/contrib/admin/templates/registration/password_reset_form.html @@ -8,12 +8,10 @@ {% endblock %} -{% block title %}{% trans "Password reset" %}{% endblock %} - +{% block title %}{{ title }}{% endblock %} +{% block content_title %}

{{ title }}

{% endblock %} {% block content %} -

{% trans "Password reset" %}

-

{% trans "Forgotten your password? Enter your email address below, and we'll email instructions for setting a new one." %}

{% csrf_token %} diff --git a/django/contrib/auth/tests/test_templates.py b/django/contrib/auth/tests/test_templates.py new file mode 100644 index 00000000000..f7d74748a25 --- /dev/null +++ b/django/contrib/auth/tests/test_templates.py @@ -0,0 +1,59 @@ +from django.contrib.auth import authenticate +from django.contrib.auth.models import User +from django.contrib.auth.tests.utils import skipIfCustomUser +from django.contrib.auth.tokens import PasswordResetTokenGenerator +from django.contrib.auth.views import ( + password_reset, password_reset_done, password_reset_confirm, + password_reset_complete, password_change, password_change_done, +) +from django.test import RequestFactory, TestCase +from django.test.utils import override_settings +from django.utils.encoding import force_bytes, force_text +from django.utils.http import urlsafe_base64_encode + + +@skipIfCustomUser +@override_settings( + PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',), +) +class AuthTemplateTests(TestCase): + + def test_titles(self): + rf = RequestFactory() + user = User.objects.create_user('jsmith', 'jsmith@example.com', 'pass') + user = authenticate(username=user.username, password='pass') + request = rf.get('/somepath/') + request.user = user + + response = password_reset(request, post_reset_redirect='dummy/') + self.assertContains(response, 'Password reset') + self.assertContains(response, '

Password reset

') + + response = password_reset_done(request) + self.assertContains(response, 'Password reset successful') + self.assertContains(response, '

Password reset successful

') + + # password_reset_confirm invalid token + response = password_reset_confirm(request, uidb64='Bad', token='Bad', post_reset_redirect='dummy/') + self.assertContains(response, 'Password reset unsuccessful') + self.assertContains(response, '

Password reset unsuccessful

') + + # password_reset_confirm valid token + default_token_generator = PasswordResetTokenGenerator() + token = default_token_generator.make_token(user) + uidb64 = force_text(urlsafe_base64_encode(force_bytes(user.pk))) + response = password_reset_confirm(request, uidb64, token, post_reset_redirect='dummy/') + self.assertContains(response, 'Enter new password') + self.assertContains(response, '

Enter new password

') + + response = password_reset_complete(request) + self.assertContains(response, 'Password reset complete') + self.assertContains(response, '

Password reset complete

') + + response = password_change(request, post_change_redirect='dummy/') + self.assertContains(response, 'Password change') + self.assertContains(response, '

Password change

') + + response = password_change_done(request) + self.assertContains(response, 'Password change successful') + self.assertContains(response, '

Password change successful

') diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py index b731a2b3d1a..d42d9574884 100644 --- a/django/contrib/auth/views.py +++ b/django/contrib/auth/views.py @@ -165,6 +165,7 @@ def password_reset(request, is_admin_site=False, form = password_reset_form() context = { 'form': form, + 'title': _('Password reset'), } if extra_context is not None: context.update(extra_context) @@ -175,7 +176,9 @@ def password_reset(request, is_admin_site=False, def password_reset_done(request, template_name='registration/password_reset_done.html', current_app=None, extra_context=None): - context = {} + context = { + 'title': _('Password reset successful'), + } if extra_context is not None: context.update(extra_context) return TemplateResponse(request, template_name, context, @@ -209,6 +212,7 @@ def password_reset_confirm(request, uidb64=None, token=None, if user is not None and token_generator.check_token(user, token): validlink = True + title = _('Enter new password') if request.method == 'POST': form = set_password_form(user, request.POST) if form.is_valid(): @@ -219,8 +223,10 @@ def password_reset_confirm(request, uidb64=None, token=None, else: validlink = False form = None + title = _('Password reset unsuccessful') context = { 'form': form, + 'title': title, 'validlink': validlink, } if extra_context is not None: @@ -232,7 +238,8 @@ def password_reset_complete(request, template_name='registration/password_reset_complete.html', current_app=None, extra_context=None): context = { - 'login_url': resolve_url(settings.LOGIN_URL) + 'login_url': resolve_url(settings.LOGIN_URL), + 'title': _('Password reset complete'), } if extra_context is not None: context.update(extra_context) @@ -261,6 +268,7 @@ def password_change(request, form = password_change_form(user=request.user) context = { 'form': form, + 'title': _('Password change'), } if extra_context is not None: context.update(extra_context) @@ -272,7 +280,9 @@ def password_change(request, def password_change_done(request, template_name='registration/password_change_done.html', current_app=None, extra_context=None): - context = {} + context = { + 'title': _('Password change successful'), + } if extra_context is not None: context.update(extra_context) return TemplateResponse(request, template_name, context,