progress towards fixing login backend
This commit is contained in:
parent
462a64fd81
commit
019c7a191a
18
app/bloonsa_game/migrations/0025_alter_level_title.py
Normal file
18
app/bloonsa_game/migrations/0025_alter_level_title.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.6 on 2025-02-21 03:42
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('bloonsa_game', '0024_config'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='level',
|
||||||
|
name='title',
|
||||||
|
field=models.CharField(max_length=64),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -123,6 +123,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
AUTHENTICATION_BACKENDS = (
|
||||||
|
"users.backends.CaseInsensitiveModelBackend", # inherits from 'django.contrib.auth.backends.ModelBackend'
|
||||||
|
)
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
||||||
|
|||||||
21
app/users/backends.py
Normal file
21
app/users/backends.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
from django.contrib.auth.backends import ModelBackend
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
from users.models import User
|
||||||
|
|
||||||
|
class CaseInsensitiveModelBackend(ModelBackend):
|
||||||
|
def authenticate(self, username=None, password=None, **kwargs):
|
||||||
|
UserModel = get_user_model()
|
||||||
|
if username is None:
|
||||||
|
username = kwargs.get(UserModel.USERNAME_FIELD)
|
||||||
|
try:
|
||||||
|
d = {'%s__iexact'%UserModel.USERNAME_FIELD: username}
|
||||||
|
user = UserModel.objects.get(**d)
|
||||||
|
if user.check_password(password):
|
||||||
|
return user
|
||||||
|
except UserModel.DoesNotExist:
|
||||||
|
# Run the default password hasher once to reduce the timing
|
||||||
|
# difference between an existing and a non-existing user (#20760).
|
||||||
|
UserModel().set_password(password)
|
||||||
|
|
||||||
|
return None
|
||||||
Loading…
Reference in New Issue
Block a user