From 9c504e485be1758ee01e7f577b9649633daae6ca Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Tue, 9 Mar 2010 04:41:43 -0500 Subject: [PATCH] Lookup users in LDAP while auto-creating --- django/mit/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/django/mit/__init__.py b/django/mit/__init__.py index e496dbd..fd8d452 100644 --- a/django/mit/__init__.py +++ b/django/mit/__init__.py @@ -17,3 +17,17 @@ class ScriptsRemoteUserBackend(RemoteUserBackend): return name else: return username + def configure_user(self, user, ): + username = user.username + import ldap + con = ldap.open('ldap.mit.edu') + con.simple_bind_s("", "") + dn = "dc=mit,dc=edu" + fields = ['cn', 'sn', 'givenName', 'mail', ] + result = con.search_s('dc=mit,dc=edu', ldap.SCOPE_SUBTREE, 'uid=%s'%username, fields) + if len(result) == 1: + user.first_name = result[0][1]['givenName'][0] + user.last_name = result[0][1]['sn'][0] + user.email = result[0][1]['mail'][0] + user.save() + return user -- 2.45.0