You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
538 B

from django.contrib.auth.backends import ModelBackend
from django.core.exceptions import MultipleObjectsReturned
from .models import CustomUser
class PhoneAuthenticationBackend(ModelBackend):
def authenticate(self, request, phone=None, password=None, **kwargs):
try:
user = CustomUser.objects.get(phone=phone)
if user.check_password(password):
return user
except CustomUser.DoesNotExist:
return None
except MultipleObjectsReturned:
return None