update location filter

This commit is contained in:
Mohamed Nouffer
2022-10-06 17:42:12 +05:30
parent 29490698f5
commit 3ad357f417
10 changed files with 154 additions and 22 deletions

28
rog/backend.py Normal file
View File

@ -0,0 +1,28 @@
from django.conf import settings
#from django.contrib.auth import get_user_model
from .models import CustomUser
from django.contrib.auth.backends import ModelBackend
class EmailOrUsernameModelBackend(ModelBackend):
"""
This is a ModelBacked that allows authentication
with either a username or an email address.
"""
def authenticate(self, username=None, password=None):
if '@' in username:
kwargs = {'email': username}
else:
kwargs = {'username': username}
try:
user = CustomUser.objects.get(**kwargs)
if user.check_password(password):
return user
except User.DoesNotExist:
return None
def get_user(self, username):
try:
return CustomUser.objects.get(pk=username)
except get_user_model().DoesNotExist:
return None