2019-12-10 22:53:50 +05:00
|
|
|
import logging
|
|
|
|
|
|
2026-10-02 11:54:47 +01:00
|
|
|
from django.conf import settings
|
2019-12-19 14:03:25 +05:00
|
|
|
from django.contrib.auth.backends import ModelBackend
|
2026-10-02 11:54:47 +01:00
|
|
|
|
2019-12-10 22:53:50 +05:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
2019-12-13 20:37:30 +05:00
|
|
|
|
2019-12-19 14:03:25 +05:00
|
|
|
class MyLDAPBackend(ModelBackend):
|
2026-10-02 11:54:47 +01:00
|
|
|
|
|
|
|
|
def authenticate(self, request, username=None, password=None, **kwargs):
|
|
|
|
|
user = super().authenticate(
|
|
|
|
|
request=request,
|
|
|
|
|
username=username,
|
|
|
|
|
password=password,
|
|
|
|
|
**kwargs
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if user and not settings.DEBUG:
|
2019-12-14 14:29:45 +05:00
|
|
|
user.create_ldap_account(password)
|
2026-10-02 11:54:47 +01:00
|
|
|
|
|
|
|
|
return user
|