Requête LDAP pour avoir les noms des gens

This commit is contained in:
champeno 2015-10-02 23:23:29 +02:00
parent 456fb50a47
commit 59e1840308
2 changed files with 21 additions and 2 deletions

View file

@ -10,6 +10,8 @@ from taggit.managers import TaggableManager
from monstage.listepays import PAYS_CHOICES
import ldap
TYPE_STAGE_CHOICES = (
('stage', _(u"Stage")),
)
@ -41,6 +43,22 @@ class Normalien(models.Model):
def create_user_profile(sender, instance, created, **kwargs):
if created:
Normalien.objects.get_or_create(user = instance)
try:
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
l = ldap.initialize("ldaps://ldap.spi.ens.fr:636")
l.set_option(ldap.OPT_REFERRALS, 0)
l.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
l.set_option(ldap.OPT_X_TLS,ldap.OPT_X_TLS_DEMAND)
l.set_option( ldap.OPT_X_TLS_DEMAND, True )
l.set_option( ldap.OPT_DEBUG_LEVEL, 255 )
info = l.search_s('dc=spi,dc=ens,dc=fr',ldap.SCOPE_SUBTREE,'(uid=%s)' % (instance.username,),['cn','mail'])
if len(info) > 0:
noms = info[0][1]['cn'][0].split(" ")
instance.first_name = noms[0]
instance.last_name = ' '.join(noms[1:])
instance.save()
except ldap.LDAPError:
pass
post_save.connect(create_user_profile, sender = User)
class Lieu(models.Model):

View file

@ -1,5 +1,6 @@
django>=1.7
django-cas-ng
django-cas (patched)
psycopg2
postgis
django-taggit
django-taggit
python-ldap