This repository has been archived on 2026-10-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
neuf-userinfo/neuf_userinfo/backends.py
T
nikolark 79a14fca02 Major update on the way to less users in LDAP
- Adds new app inside with models and moves related logic.
- Working InsideAuthBackend with group sync
- use passlib (<3) for MySQL hashes
- Renames main app to neuf_userinfo
- introduced local_settings.py
2015-02-14 22:54:36 +01:00

30 lines
980 B
Python

from django_auth_ldap.backend import LDAPBackend
class LDAPUsernameBackend(LDAPBackend):
settings_prefix = "AUTH_LDAP_U_"
class LDAPEmailBackend(LDAPBackend):
settings_prefix = "AUTH_LDAP_E_"
def get_or_create_user(self, email, ldap_user):
"""
Use the PosixUser uid field as username instead of email.
This must return a (User, created) 2-tuple for the given LDAP user.
username is the Django-friendly username of the user. ldap_user.dn is
the user's DN and ldap_user.attrs contains all of their LDAP attributes.
"""
model = self.get_user_model()
username_field = getattr(model, 'USERNAME_FIELD', 'username')
kwargs = {
username_field + '__iexact': ldap_user.attrs['uid'][0],
'defaults': {
username_field: ldap_user.attrs['uid'][0].lower(),
'email': email
}
}
return model.objects.get_or_create(**kwargs)