Ticket #11061: adminsite.patch

File adminsite.patch, 1.9 KB (added by vvd, 6 years ago)
  • django/contrib/admin/sites.py

     
    293293        user = authenticate(username=username, password=password)
    294294        if user is None:
    295295            message = ERROR_MESSAGE
    296             if u'@' in username:
     296            if username is not None and u'@' in username:
    297297                # Mistakenly entered e-mail address instead of username? Look it up.
    298298                try:
    299299                    user = User.objects.get(email=username)
  • tests/regressiontests/admin_views/tests.py

     
    347347                     LOGIN_FORM_KEY: 1,
    348348                     'username': 'joepublic',
    349349                     'password': 'secret'}
     350        self.no_username_login = {
     351                     LOGIN_FORM_KEY: 1,
     352                     'password': 'secret'}
    350353
    351354    def testLogin(self):
    352355        """
     
    410413        # Login.context is a list of context dicts we just need to check the first one.
    411414        self.assert_(login.context[0].get('error_message'))
    412415
     416        # Requests without username should not fail
     417        request = self.client.get('/test_admin/admin/')
     418        self.failUnlessEqual(request.status_code, 200)
     419        login = self.client.post('/test_admin/admin/', self.no_username_login)
     420        self.failUnlessEqual(login.status_code, 200)
     421        # Login.context is a list of context dicts we just need to check the first one.
     422        self.assert_(login.context[0].get('error_message'))
     423       
     424
    413425    def testLoginSuccessfullyRedirectsToOriginalUrl(self):
    414426        request = self.client.get('/test_admin/admin/')
    415427        self.failUnlessEqual(request.status_code, 200)
Back to Top