refactor(backends): try authenticating as superuser/admin and staff by phone first
This commit is contained in:
1 parent
0f1f5b017c
commit
cbd129df0c
1 file changed
+15
@@ -15,6 +15,14 @@ class MultiModelBackend(ModelBackend):
|
||||
if username is None or password is None:
|
||||
return None
|
||||
|
||||
# Try authenticating as superuser/admin first
|
||||
try:
|
||||
user = User.objects.get(email=username)
|
||||
if user.check_password(password):
|
||||
return user
|
||||
except User.DoesNotExist:
|
||||
pass
|
||||
|
||||
# Try authenticating as Staff by phone first
|
||||
staff = Staff.objects.filter(phone=username).first()
|
||||
if staff:
|
||||
@@ -52,6 +60,13 @@ class MultiModelBackend(ModelBackend):
|
||||
"""
|
||||
Retrieve a user instance using their ID.
|
||||
"""
|
||||
# Try to get superuser/admin first
|
||||
try:
|
||||
return User.objects.get(pk=user_id)
|
||||
except User.DoesNotExist:
|
||||
pass
|
||||
|
||||
# Try other user types
|
||||
for model in [Staff, Student, Parent]:
|
||||
try:
|
||||
return model.objects.get(pk=user_id)
|
||||
|
||||
Reference in new issue
Block a user