I have written a custom authentication middleware, that authenticates users based on email field and not username, but now I am unable to log into the Admin Panel of Django, using email of the Superuser/staff:
def authenticate(self, username=None, password=None):
# Passing email as username
try:
user = User.objects.get(email=username)
if user.check_password(password):
return user
except User.DoesNotExist:
return None
def get_user(self, user_id):
# Get User Object from user_id
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
It would be great if someone could help me through this?