mirror of
				https://github.com/django/django.git
				synced 2025-11-04 05:35:37 +00:00 
			
		
		
		
	Admin app login form should use swapped user model
This commit is contained in:
		
							parent
							
								
									7e82e83d67
								
							
						
					
					
						commit
						d088b3af58
					
				
					 1 changed files with 4 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -4,7 +4,7 @@ from django import forms
 | 
			
		|||
 | 
			
		||||
from django.contrib.auth import authenticate
 | 
			
		||||
from django.contrib.auth.forms import AuthenticationForm
 | 
			
		||||
from django.contrib.auth.models import User
 | 
			
		||||
from django.contrib.auth import get_user_model
 | 
			
		||||
from django.utils.translation import ugettext_lazy, ugettext as _
 | 
			
		||||
 | 
			
		||||
ERROR_MESSAGE = ugettext_lazy("Please enter the correct username and password "
 | 
			
		||||
| 
						 | 
				
			
			@ -29,9 +29,10 @@ class AdminAuthenticationForm(AuthenticationForm):
 | 
			
		|||
            if self.user_cache is None:
 | 
			
		||||
                if '@' in username:
 | 
			
		||||
                    # Mistakenly entered e-mail address instead of username? Look it up.
 | 
			
		||||
                    user_model = get_user_model()
 | 
			
		||||
                    try:
 | 
			
		||||
                        user = User.objects.get(email=username)
 | 
			
		||||
                    except (User.DoesNotExist, User.MultipleObjectsReturned):
 | 
			
		||||
                        user = user_model.objects.get(email=username)
 | 
			
		||||
                    except (user_model.DoesNotExist, user_model.MultipleObjectsReturned):
 | 
			
		||||
                        # Nothing to do here, moving along.
 | 
			
		||||
                        pass
 | 
			
		||||
                    else:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue