Files
n3wt-school/Back-End/Auth/backends.py
2025-01-12 10:07:06 +01:00

21 lines
622 B
Python

from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend
from Auth.models import Profile
from N3wtSchool import bdd
class EmailBackend(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
if username is None:
username = kwargs.get(Profile.USERNAME_FIELD)
try:
user = Profile.objects.get(email=username)
# Vérifie le mot de passe de l'utilisateur
if user.check_password(password):
return user
except Profile.DoesNotExist:
return None