I'm writing a web app with django and an Ldap backend to authenticate users. Authentication is done, and attribute mapping is also done with django-auth-ldap (thanks ...). But in the web interface, users need to update some informations like description, phone etc ...
So i need to retrive the dn attribute to update current user and not another. I try to map the distinguish name with and an attribute but not working... Any ideas ?
Please find below current code.
settings.py :
AUTH_LDAP_USER_ATTR_MAP = {
"dn" : "ldap_user.dn",
"name": "cn",
"description": "description",
"employeeType": "employeeType",
... }
but no resutls...
And i try also to write in my view :
def update_description(request):
if request.method == "POST":
form = DescriptionUpdateForm(request.POST)
if form.is_valid():
description = form.cleaned_data['description']
user = request.user
old_description = user.description
user.description = description
user.save()
try:
l = ldap.initialize(settings.AUTH_LDAP_SERVER_URI)
l.simple_bind_s(settings.AUTH_LDAP_BIND_DN, settings.AUTH_LDAP_BIND_PASSWORD)
user_ldap_dn = LDAPBackend().django_to_ldap_username(user.email).dn
l.unbind_s()
except ldap.LDAPError, e:
print e
return HttpResponseRedirect('/user/profile')
else:
form = DescriptionUpdateForm()
return render(request, 'edit_description.html', {'form': form,})
But no result, i can't retrive the dn entry for this user...
Thanks in advance, Loic.