Lookup users in LDAP while auto-creating
authorAlex Dehnert <adehnert@mit.edu>
Tue, 9 Mar 2010 09:41:43 +0000 (04:41 -0500)
committerAlex Dehnert <adehnert@mit.edu>
Mon, 6 Jun 2011 05:57:09 +0000 (01:57 -0400)
django/mit/__init__.py

index e496dbd9472cafb7cbb99e67a04bc01a079441e1..fd8d4529fb1ecfc81ae9ddd67213b0398e1cd5ab 100644 (file)
@@ -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