diff options
author | 2011-07-05 05:14:38 +0300 | |
---|---|---|
committer | 2011-07-05 05:14:38 +0300 | |
commit | cdb33845366299b5fba8542704f615a99f8595bc (patch) | |
tree | c7e5023dfa3ca56c6e99563bb74391aa19228efd | |
parent | Remove prints (diff) | |
download | identity.gentoo.org-cdb33845366299b5fba8542704f615a99f8595bc.tar.gz identity.gentoo.org-cdb33845366299b5fba8542704f615a99f8595bc.tar.bz2 identity.gentoo.org-cdb33845366299b5fba8542704f615a99f8595bc.zip |
New ldap function: ldap_current_user_bind, binds with the credentials of
the currently logged in user
-rw-r--r-- | accounts/views.py | 9 | ||||
-rw-r--r-- | libraries/ldap_wrappers.py | 14 |
2 files changed, 15 insertions, 8 deletions
diff --git a/accounts/views.py b/accounts/views.py index e7be5e0..33efef0 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -135,14 +135,7 @@ def account_edit_password(request, username): if form.is_valid(): if form.cleaned_data['password1'] != form.cleaned_data['password2']: raise OkupyException('Passwords don\'t match') - l = '' - for base_dn in settings.LDAP_BASE_DN: - try: - l = ldap_bind(username = username, password = form.cleaned_data['old_password'], base_dn = base_dn) - except: - pass - if l: - break + l = ldap_current_user_bind(username = username, password = form.cleaned_data['old_password']) if l: user = ldap_user_search(filter = username, l = l) else: diff --git a/libraries/ldap_wrappers.py b/libraries/ldap_wrappers.py index 54f7cd9..0ec00e7 100644 --- a/libraries/ldap_wrappers.py +++ b/libraries/ldap_wrappers.py @@ -83,6 +83,20 @@ def ldap_admin_user_bind(): l = None return l +def ldap_current_user_bind(username, password): + ''' + Bind with the credentials of the currently logged in user + ''' + l = '' + for base_dn in settings.LDAP_BASE_DN: + try: + l = ldap_bind(username = username, password = password, base_dn = base_dn) + except: + pass + if l: + return l + return None + def ldap_user_search(filter = '*', attr = settings.LDAP_BASE_ATTR, results = None, anon = True, l = False): if anon: l = ldap_anon_user_bind() |