From 59e18403083e41152d167a0b1dd2b461b9a5cabd Mon Sep 17 00:00:00 2001 From: champeno Date: Fri, 2 Oct 2015 23:23:29 +0200 Subject: [PATCH] =?UTF-8?q?Requ=C3=AAte=20LDAP=20pour=20avoir=20les=20noms?= =?UTF-8?q?=20des=20gens?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monstage/models.py | 18 ++++++++++++++++++ requirements.txt | 5 +++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/monstage/models.py b/monstage/models.py index bb22d3c..1a8699e 100644 --- a/monstage/models.py +++ b/monstage/models.py @@ -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): diff --git a/requirements.txt b/requirements.txt index 3e8e341..9b2580a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ django>=1.7 -django-cas-ng +django-cas (patched) psycopg2 postgis -django-taggit \ No newline at end of file +django-taggit +python-ldap \ No newline at end of file