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.
17 lines
605 B
17 lines
605 B
from django.contrib.auth.backends import ModelBackend
|
|
from django.contrib.auth import get_user_model
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class CaseInsensitiveModelBackend(ModelBackend):
|
|
|
|
def authenticate(self, request, username=None, password=None, **kwargs):
|
|
if username is None:
|
|
username = kwargs.get(User.USERNAME_FIELD)
|
|
try:
|
|
user = User.objects.get(**{f'{User.USERNAME_FIELD}__iexact': username})
|
|
if user.check_password(password) and self.user_can_authenticate(user):
|
|
return user
|
|
except User.DoesNotExist:
|
|
return None
|
|
|