Update authenthication code to support multitenants. Replace all remaining instances of hardcoded User model.
This commit is contained in:
20
mayan/apps/authentication/auth/model_auth_backend.py
Normal file
20
mayan/apps/authentication/auth/model_auth_backend.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.backends import ModelBackend
|
||||
|
||||
|
||||
class UsernameModelBackend(ModelBackend):
|
||||
def authenticate(self, username=None, password=None, **kwargs):
|
||||
UserModel = get_user_model()
|
||||
if username is None:
|
||||
username = kwargs.get(UserModel.USERNAME_FIELD)
|
||||
try:
|
||||
user = UserModel.on_organization.get(username=username)
|
||||
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)
|
||||
Reference in New Issue
Block a user