From 519169e49eeaa89ae7022428c0ee02740adb56c3 Mon Sep 17 00:00:00 2001 From: seba Date: Tue, 8 Mar 2011 19:13:22 +0100 Subject: [PATCH] ldap working + automatic userprofile creation whuppie :) --- k4ever/main/models.py | 10 ++++++++++ k4ever/settings.py | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/k4ever/main/models.py b/k4ever/main/models.py index 33eb976..31aa75b 100644 --- a/k4ever/main/models.py +++ b/k4ever/main/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.db.models.signals import post_save from django.contrib.auth.models import User class UserProfile(models.Model): @@ -7,3 +8,12 @@ class UserProfile(models.Model): def __unicode__(self): return "%s (Kontostand: %s)" % (self.user ,self.balance) + +def createUserProfile(sender, instance, created, **kwargs): + if created: + profile = UserProfile() + profile.user = instance + profile.save() + +post_save.connect(createUserProfile, sender=User) + diff --git a/k4ever/settings.py b/k4ever/settings.py index 01c2891..dd9f543 100644 --- a/k4ever/settings.py +++ b/k4ever/settings.py @@ -71,8 +71,8 @@ LOGIN_URL = '/user/login/' LOGIN_REDIRECT_URL = '/' AUTHENTICATION_BACKENDS = ( - 'main.backend.CustomLDAPBackend', -# 'django_auth_ldap.backend.LDAPBackend', +# 'main.backend.CustomLDAPBackend', + 'django_auth_ldap.backend.LDAPBackend', 'django.contrib.auth.backends.ModelBackend', ) @@ -80,7 +80,7 @@ AUTHENTICATION_BACKENDS = ( AUTH_LDAP_SERVER_URI = 'ldaps://chef.freitagsrunde.org' AUTH_LDAP_START_TLS = False # we already use LDAPS AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=users,dc=freitagsrunde,dc=org" -AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName", "last_name": "sn"} +AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName", "last_name": "sn", "email": "mail"} AUTH_LDAP_GLOBAL_OPTIONS = {ldap.OPT_X_TLS_CACERTFILE: "data/cacert.txt"} ## Nur ein Beispiel, falls technik@ automatisch admin der Kasse werden soll.