From 2a4aa8bcf7be28bac9d5ed6a029c2c3f52f389e7 Mon Sep 17 00:00:00 2001 From: Paul McMillan Date: Thu, 22 Sep 2011 05:36:57 +0000 Subject: [PATCH] [1.3.X] Fixed #16837 -- Improved error messages for admin login. Thanks Wim Feijen for the patch. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@16878 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/forms.py | 4 ++-- tests/regressiontests/admin_views/tests.py | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/django/contrib/admin/forms.py b/django/contrib/admin/forms.py index f26c10014d..e790e2e3b6 100644 --- a/django/contrib/admin/forms.py +++ b/django/contrib/admin/forms.py @@ -6,8 +6,8 @@ from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy, ugettext as _ -ERROR_MESSAGE = ugettext_lazy("Please enter a correct username and password. " - "Note that both fields are case-sensitive.") +ERROR_MESSAGE = ugettext_lazy("Please enter the correct username and password " + "for a staff account. Note that both fields are case-sensitive.") class AdminAuthenticationForm(AuthenticationForm): """ diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 57bd87f8e6..7f4b05fab6 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -38,6 +38,9 @@ from models import (Article, BarAccount, CustomArticle, EmptyModel, Question, Answer, Inquisition, Actor, FoodDelivery, RowLevelChangePermissionModel, Paper, CoverLetter, Story, OtherStory) +ERROR_MESSAGE = "Please enter the correct username and password \ +for a staff account. Note that both fields are case-sensitive." + class AdminViewBasicTest(TestCase): fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', @@ -638,12 +641,12 @@ class AdminViewPermissionsTest(TestCase): self.assertContains(login, "Your e-mail address is not your username") # only correct passwords get a username hint login = self.client.post('/test_admin/admin/', self.super_email_bad_login) - self.assertContains(login, "Please enter a correct username and password.") + self.assertContains(login, ERROR_MESSAGE) new_user = User(username='jondoe', password='secret', email='super@example.com') new_user.save() # check to ensure if there are multiple e-mail addresses a user doesn't get a 500 login = self.client.post('/test_admin/admin/', self.super_email_login) - self.assertContains(login, "Please enter a correct username and password.") + self.assertContains(login, ERROR_MESSAGE) # Add User request = self.client.get('/test_admin/admin/') @@ -674,7 +677,7 @@ class AdminViewPermissionsTest(TestCase): self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/', self.joepublic_login) self.assertEqual(login.status_code, 200) - self.assertContains(login, "Please enter a correct username and password.") + self.assertContains(login, ERROR_MESSAGE) # Requests without username should not return 500 errors. request = self.client.get('/test_admin/admin/') @@ -1234,12 +1237,12 @@ class SecureViewTests(TestCase): self.assertContains(login, "Your e-mail address is not your username") # only correct passwords get a username hint login = self.client.post('/test_admin/admin/secure-view/', self.super_email_bad_login) - self.assertContains(login, "Please enter a correct username and password.") + self.assertContains(login, ERROR_MESSAGE) new_user = User(username='jondoe', password='secret', email='super@example.com') new_user.save() # check to ensure if there are multiple e-mail addresses a user doesn't get a 500 login = self.client.post('/test_admin/admin/secure-view/', self.super_email_login) - self.assertContains(login, "Please enter a correct username and password.") + self.assertContains(login, ERROR_MESSAGE) # Add User request = self.client.get('/test_admin/admin/secure-view/') @@ -1271,7 +1274,7 @@ class SecureViewTests(TestCase): login = self.client.post('/test_admin/admin/secure-view/', self.joepublic_login) self.assertEqual(login.status_code, 200) # Login.context is a list of context dicts we just need to check the first one. - self.assertContains(login, "Please enter a correct username and password.") + self.assertContains(login, ERROR_MESSAGE) # 8509 - if a normal user is already logged in, it is possible # to change user into the superuser without error