This commit is contained in:
2026-03-25 16:19:28 +03:30
parent 2846db1647
commit f305e00cfe
7 changed files with 63 additions and 121 deletions
+2 -7
View File
@@ -6,10 +6,7 @@ User = get_user_model()
class MultiFieldBackend(ModelBackend):
"""
Authenticate against username, email, or phone_number.
Used for password-based login where the user can enter any of the three.
"""
"""Authenticate with username, email, or phone_number."""
def authenticate(self, request, username=None, password=None, **kwargs):
if username is None or password is None:
@@ -19,12 +16,10 @@ class MultiFieldBackend(ModelBackend):
user = User.objects.get(
Q(username=username) | Q(email=username) | Q(phone_number=username)
)
print(user)
except (User.DoesNotExist, User.MultipleObjectsReturned):
User().set_password(password)
return None
print(user.check_password(password) , self.user_can_authenticate(user))
if user.check_password(password) and self.user_can_authenticate(user):
return user
return None