From a607d9d34546a4ff9313d431e275ed0bf365d42a Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Thu, 2 Dec 2010 01:02:11 +0000 Subject: [PATCH] [1.2.X] Fixed #8342 -- Removed code from the admin that assumed that you can't login with an email address (nixed by r12634). Backport from trunk (r14769). git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14773 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/sites.py | 4 +--- django/contrib/admin/views/decorators.py | 4 ---- tests/regressiontests/admin_views/tests.py | 8 ++++---- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index 4446490451..1778ae40b5 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -327,13 +327,11 @@ class AdminSite(object): try: user = User.objects.get(email=username) except (User.DoesNotExist, User.MultipleObjectsReturned): - message = _("Usernames cannot contain the '@' character.") + pass else: if user.check_password(password): message = _("Your e-mail address is not your username." " Try '%s' instead.") % user.username - else: - message = _("Usernames cannot contain the '@' character.") return self.display_login_form(request, message) # The user data is correct; log in the user in and continue. diff --git a/django/contrib/admin/views/decorators.py b/django/contrib/admin/views/decorators.py index afdc07589d..82184fc9d3 100644 --- a/django/contrib/admin/views/decorators.py +++ b/django/contrib/admin/views/decorators.py @@ -60,10 +60,6 @@ def staff_member_required(view_func): users = list(User.objects.filter(email=username)) if len(users) == 1 and users[0].check_password(password): message = _("Your e-mail address is not your username. Try '%s' instead.") % users[0].username - else: - # Either we cannot find the user, or if more than 1 - # we cannot guess which user is the correct one. - message = _("Usernames cannot contain the '@' character.") return _display_login_form(request, message) # The user data is correct; log in the user in and continue. diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 8fea95bf6a..f5da6b017e 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -453,12 +453,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, "Usernames cannot contain the '@' character") + self.assertContains(login, "Please enter a correct username and password") 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, "Usernames cannot contain the '@' character") + self.assertContains(login, "Please enter a correct username and password") # Add User request = self.client.get('/test_admin/admin/') @@ -962,12 +962,12 @@ class SecureViewTest(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, "Usernames cannot contain the '@' character") + self.assertContains(login, "Please enter a correct username and password") 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, "Usernames cannot contain the '@' character") + self.assertContains(login, "Please enter a correct username and password") # Add User request = self.client.get('/test_admin/admin/secure-view/')