diff --git a/utils/backend.py b/utils/backend.py index cbf38d6c..2b5c86e5 100644 --- a/utils/backend.py +++ b/utils/backend.py @@ -1,26 +1,13 @@ import logging -from membership.models import CustomUser +from django.contrib.auth.backends import ModelBackend logger = logging.getLogger(__name__) -class MyLDAPBackend(object): - def authenticate(self, email, password): - try: - user = CustomUser.objects.get(email=email) - except CustomUser.DoesNotExist: - # User does not exists in Database - return None - else: +class MyLDAPBackend(ModelBackend): + def authenticate(self, username=None, password=None, **kwargs): + user = super().authenticate(username, password, **kwargs) + if user: user.create_ldap_account(password) - if user.check_password(password): - return user - else: - return None - - def get_user(self, user_id): - try: - return CustomUser.objects.get(pk=user_id) - except CustomUser.DoesNotExist: - return None + return user