dynamicweb/utils/backend.py

27 lines
656 B
Python
Raw Normal View History

2019-12-10 22:53:50 +05:00
import logging
2026-10-04 18:36:54 +01:00
import sys
2019-12-10 22:53:50 +05:00
2026-10-02 11:54:47 +01:00
from django.conf import settings
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__)
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
)
2026-10-04 18:36:54 +01:00
is_testing = (
"test" in sys.argv
or "pytest" in sys.modules
)
if user and not settings.DEBUG and not is_testing:
user.create_ldap_account(password)
2026-10-02 11:54:47 +01:00
return user