diff options
author | equinox <equinox@diac24.net> | 2011-09-27 01:14:35 +0200 |
---|---|---|
committer | equinox <equinox@diac24.net> | 2011-09-27 02:08:40 +0200 |
commit | ed927fd7ccafebfa68dc327c7389876131a9a870 (patch) | |
tree | 655f5945a362e22f9d72f8f4bc6437a46119378e | |
parent | 628b4ee18af872ba51e8f07a5b5d2854b1721b2e (diff) |
python: separate login method
-rwxr-xr-x | index.py | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -35,6 +35,9 @@ class ldapobj(object): def keys(s): return s._keys +class LoginError(Exception): + pass + class SubdapSite(object): def __init__(s): cherrypy.config.update({'error_page.404': s.http_404}) @@ -46,22 +49,29 @@ class SubdapSite(object): @expose('login.html') def index(s): return render(errors = {}) - @expose('login.html') - def login(s, username = None, password = None): - if username == None or password == None: - return render(errors = {'password': 'Login incorrect'}) - if username == '' or password == '': - return render(errors = {'password': 'Login incorrect'}) + def login_perform(s, username, password): dn = "cn=%s,ou=people,dc=sublab,dc=org" % (username) try: l = ldap.initialize('ldaps://taifun.local.sublab.org/') l.simple_bind_s(dn, password) except ldap.INVALID_CREDENTIALS: - return render(errors = {'password': 'Login incorrect'}) + raise LoginError('Login incorrect') except ldap.LDAPError, e: - return render(errors = {'password': 'Login incorrect'}) + raise LoginError('Login incorrect') # e.message['info'] + return (l, dn) + + @expose('login.html') + def login(s, username = None, password = None): + if username == None or password == None: + return render(errors = {'password': 'Login incorrect'}) + if username == '' or password == '': + return render(errors = {'password': 'Login incorrect'}) + + try: l, dn = s.login_perform(username, password) + except LoginError, e: + return render(errors = {'password': str(e)}) user = ldapobj(l.search_s(dn, ldap.SCOPE_BASE, '(objectclass=*)', [])) |