Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #18511 -- Cleaned up admin password reset template titles.

  • Loading branch information...
commit e07e4030b9170d522a9670a80c4fd40acff369cb 1 parent 8676318
@cobalys cobalys authored timgraham committed
View
8 django/contrib/admin/templates/registration/password_change_done.html
@@ -8,12 +8,8 @@
</div>
{% endblock %}
-{% block title %}{% trans 'Password change successful' %}{% endblock %}
-
+{% block title %}{{ title }}{% endblock %}
+{% block content_title %}<h1>{{ title }}</h1>{% endblock %}
{% block content %}
-
-<h1>{% trans 'Password change successful' %}</h1>
-
<p>{% trans 'Your password was changed.' %}</p>
-
{% endblock %}
View
4 django/contrib/admin/templates/registration/password_change_form.html
@@ -9,7 +9,8 @@
</div>
{% endblock %}
-{% block title %}{% trans 'Password change' %}{% endblock %}
+{% block title %}{{ title }}{% endblock %}
+{% block content_title %}<h1>{{ title }}</h1>{% endblock %}
{% block content %}<div id="content-main">
@@ -21,7 +22,6 @@
</p>
{% endif %}
-<h1>{% trans 'Password change' %}</h1>
<p>{% 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." %}</p>
View
5 django/contrib/admin/templates/registration/password_reset_complete.html
@@ -8,12 +8,11 @@
</div>
{% endblock %}
-{% block title %}{% trans 'Password reset complete' %}{% endblock %}
+{% block title %}{{ title }}{% endblock %}
+{% block content_title %}<h1>{{ title }}</h1>{% endblock %}
{% block content %}
-<h1>{% trans 'Password reset complete' %}</h1>
-
<p>{% trans "Your password has been set. You may go ahead and log in now." %}</p>
<p><a href="{{ login_url }}">{% trans 'Log in' %}</a></p>
View
8 django/contrib/admin/templates/registration/password_reset_confirm.html
@@ -8,14 +8,12 @@
</div>
{% endblock %}
-{% block title %}{% trans 'Password reset' %}{% endblock %}
-
+{% block title %}{{ title }}{% endblock %}
+{% block content_title %}<h1>{{ title }}</h1>{% endblock %}
{% block content %}
{% if validlink %}
-<h1>{% trans 'Enter new password' %}</h1>
-
<p>{% trans "Please enter your new password twice so we can verify you typed it in correctly." %}</p>
<form action="" method="post">{% csrf_token %}
@@ -28,8 +26,6 @@
{% else %}
-<h1>{% trans 'Password reset unsuccessful' %}</h1>
-
<p>{% trans "The password reset link was invalid, possibly because it has already been used. Please request a new password reset." %}</p>
{% endif %}
View
6 django/contrib/admin/templates/registration/password_reset_done.html
@@ -8,12 +8,10 @@
</div>
{% endblock %}
-{% block title %}{% trans 'Password reset successful' %}{% endblock %}
-
+{% block title %}{{ title }}{% endblock %}
+{% block content_title %}<h1>{{ title }}</h1>{% endblock %}
{% block content %}
-<h1>{% trans 'Password reset successful' %}</h1>
-
<p>{% trans "We've emailed you instructions for setting your password. You should be receiving them shortly." %}</p>
<p>{% trans "If you don't receive an email, please make sure you've entered the address you registered with, and check your spam folder." %}</p>
View
6 django/contrib/admin/templates/registration/password_reset_form.html
@@ -8,12 +8,10 @@
</div>
{% endblock %}
-{% block title %}{% trans "Password reset" %}{% endblock %}
-
+{% block title %}{{ title }}{% endblock %}
+{% block content_title %}<h1>{{ title }}</h1>{% endblock %}
{% block content %}
-<h1>{% trans "Password reset" %}</h1>
-
<p>{% trans "Forgotten your password? Enter your email address below, and we'll email instructions for setting a new one." %}</p>
<form action="" method="post">{% csrf_token %}
View
59 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, '<title>Password reset</title>')
+ self.assertContains(response, '<h1>Password reset</h1>')
+
+ response = password_reset_done(request)
+ self.assertContains(response, '<title>Password reset successful</title>')
+ self.assertContains(response, '<h1>Password reset successful</h1>')
+
+ # password_reset_confirm invalid token
+ response = password_reset_confirm(request, uidb64='Bad', token='Bad', post_reset_redirect='dummy/')
+ self.assertContains(response, '<title>Password reset unsuccessful</title>')
+ self.assertContains(response, '<h1>Password reset unsuccessful</h1>')
+
+ # 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, '<title>Enter new password</title>')
+ self.assertContains(response, '<h1>Enter new password</h1>')
+
+ response = password_reset_complete(request)
+ self.assertContains(response, '<title>Password reset complete</title>')
+ self.assertContains(response, '<h1>Password reset complete</h1>')
+
+ response = password_change(request, post_change_redirect='dummy/')
+ self.assertContains(response, '<title>Password change</title>')
+ self.assertContains(response, '<h1>Password change</h1>')
+
+ response = password_change_done(request)
+ self.assertContains(response, '<title>Password change successful</title>')
+ self.assertContains(response, '<h1>Password change successful</h1>')
View
16 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,
Please sign in to comment.
Something went wrong with that request. Please try again.