Created
August 6, 2020 02:54
-
-
Save osw4l/7581c4347b7aa3d58523f510d8eba269 to your computer and use it in GitHub Desktop.
custom auth backend django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomAuthenticationBackend: | |
def authenticate(self, request, email_or_phone=None, password=None): | |
try: | |
user = User.objects.get( | |
Q(email=email_or_phone) | Q(phone=email_or_phone) | |
) | |
pwd_valid = user.check_password(password) | |
if pwd_valid: | |
return user | |
return None | |
except User.DoesNotExist: | |
return None | |
def get_user(self, user_id): | |
try: | |
return User.objects.get(pk=user_id) | |
except User.DoesNotExist: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment