Skip to content

Commit

Permalink
Fixed #16837 -- Improved error message for admin login.
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16872 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
PaulMcMillan committed Sep 22, 2011
1 parent 5a01324 commit 0781ed8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions django/contrib/admin/forms.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


from django.utils.translation import ugettext_lazy, ugettext as _ from django.utils.translation import ugettext_lazy, ugettext as _


ERROR_MESSAGE = ugettext_lazy("Please enter a correct username and password. " ERROR_MESSAGE = ugettext_lazy("Please enter the correct username and password "
"Note that both fields are case-sensitive.") "for a staff account. Note that both fields are case-sensitive.")


class AdminAuthenticationForm(AuthenticationForm): class AdminAuthenticationForm(AuthenticationForm):
""" """
Expand Down
15 changes: 9 additions & 6 deletions tests/regressiontests/admin_views/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
RowLevelChangePermissionModel, Paper, CoverLetter, Story, OtherStory, RowLevelChangePermissionModel, Paper, CoverLetter, Story, OtherStory,
ComplexSortedPerson, Parent, Child) ComplexSortedPerson, Parent, Child)


ERROR_MESSAGE = "Please enter the correct username and password \
for a staff account. Note that both fields are case-sensitive."



class AdminViewBasicTest(TestCase): class AdminViewBasicTest(TestCase):
fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', fixtures = ['admin-views-users.xml', 'admin-views-colors.xml',
Expand Down Expand Up @@ -761,12 +764,12 @@ def testLogin(self):
self.assertContains(login, "Your e-mail address is not your username") self.assertContains(login, "Your e-mail address is not your username")
# only correct passwords get a username hint # only correct passwords get a username hint
login = self.client.post('/test_admin/admin/', self.super_email_bad_login) 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 = User(username='jondoe', password='secret', email='super@example.com')
new_user.save() new_user.save()
# check to ensure if there are multiple e-mail addresses a user doesn't get a 500 # 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) 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 # Add User
request = self.client.get('/test_admin/admin/') request = self.client.get('/test_admin/admin/')
Expand Down Expand Up @@ -797,7 +800,7 @@ def testLogin(self):
self.assertEqual(request.status_code, 200) self.assertEqual(request.status_code, 200)
login = self.client.post('/test_admin/admin/', self.joepublic_login) login = self.client.post('/test_admin/admin/', self.joepublic_login)
self.assertEqual(login.status_code, 200) 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. # Requests without username should not return 500 errors.
request = self.client.get('/test_admin/admin/') request = self.client.get('/test_admin/admin/')
Expand Down Expand Up @@ -1360,12 +1363,12 @@ def test_staff_member_required_decorator_works_as_per_admin_login(self):
self.assertContains(login, "Your e-mail address is not your username") self.assertContains(login, "Your e-mail address is not your username")
# only correct passwords get a username hint # only correct passwords get a username hint
login = self.client.post('/test_admin/admin/secure-view/', self.super_email_bad_login) 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 = User(username='jondoe', password='secret', email='super@example.com')
new_user.save() new_user.save()
# check to ensure if there are multiple e-mail addresses a user doesn't get a 500 # 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) 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 # Add User
request = self.client.get('/test_admin/admin/secure-view/') request = self.client.get('/test_admin/admin/secure-view/')
Expand Down Expand Up @@ -1397,7 +1400,7 @@ def test_staff_member_required_decorator_works_as_per_admin_login(self):
login = self.client.post('/test_admin/admin/secure-view/', self.joepublic_login) login = self.client.post('/test_admin/admin/secure-view/', self.joepublic_login)
self.assertEqual(login.status_code, 200) self.assertEqual(login.status_code, 200)
# Login.context is a list of context dicts we just need to check the first one. # 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 # 8509 - if a normal user is already logged in, it is possible
# to change user into the superuser without error # to change user into the superuser without error
Expand Down

0 comments on commit 0781ed8

Please sign in to comment.