I am trying to learn from book django 3 by example but i cannot understand few points in django custom authentication like why username and password is passed None and email=username and why we are using get_user
Here is the code
from django.contrib.auth.models import User
class EmailAuthBackend(object):
#Authenticate using an e-mail address
def authenticate(self,request,username=None,password=None):
try:
user=User.objects.get(email=username)
if user.check_password(password):
return user
return None
except User.DoesNotExit:
return None
def get_user(self,user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExit:
return None