From 8d2b75d61631e0794d436eefefb25644de1d2de4 Mon Sep 17 00:00:00 2001 From: equinox Date: Tue, 27 Sep 2011 02:09:53 +0200 Subject: password change application --- index.py | 38 +++++++++++++++++++++++++++++++++----- static/app_password.png | Bin 0 -> 1927 bytes static/info.png | Bin 0 -> 1933 bytes static/layout.css | 18 ++++++++++++++++++ templates/layout.xi | 8 ++++++++ templates/pwchange.html | 23 +++++++++++++++++++++++ templates/select.html | 5 ++++- 7 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 static/app_password.png create mode 100644 static/info.png create mode 100644 templates/pwchange.html diff --git a/index.py b/index.py index 3bf8f41..8aa1c35 100755 --- a/index.py +++ b/index.py @@ -73,13 +73,16 @@ class SubdapSite(object): except LoginError, e: return render(errors = {'password': str(e)}) + return s.selectpage(l, dn) + + def selectpage(s, l, dn, message = None): user = ldapobj(l.search_s(dn, ldap.SCOPE_BASE, '(objectclass=*)', [])) tgts = {} for site in tgt_sites: tgts[site] = urllib.urlencode(ticket.tgt_create(site, user['cn'])) - return render('select.html', user = user, tgts = tgts) + return render('select.html', user = user, tgts = tgts, message = message) ## x = '' # for r in data: @@ -91,12 +94,12 @@ class SubdapSite(object): # details.append([k, value]) ## x += '%s
%s
\n' % (k, "
".join(v)) - def params_validate(s, errors, username, password, password2): + def newpass_validate(s, username, password, password2, expectstate): errors = {} if username == None or username == '': errors['username'] = 'please specify an user name' - elif accountservice.name_valid(username) != 'valid': - errors['username'] = 'username invalid or taken' + elif accountservice.name_valid(username) != expectstate: + errors['username'] = 'username invalid' if password == None or len(password) < 6: errors['password'] = 'please specify a password of at least 6 characters' if password2 != password: @@ -110,13 +113,38 @@ class SubdapSite(object): if cherrypy.request.method.upper() == 'GET': return render(errors = {}, username = '') - errors = s.params_validate(errors, username, password, password2) + errors = s.newpass_validate(username, password, password2, 'valid') if errors is not None: return render(errors = errors, username = username) accountservice.name_create(username, password) return s.login(username, password) + @expose('pwchange.html') + def pwchange(s, username = None, oldpassword = None, password = None, password2 = None): + if cherrypy.request.method.upper() == 'GET': + return render(errors = {}, username = username) + + errors = s.newpass_validate(username, password, password2, 'exists') + if errors is not None: + return render(errors = errors, username = username) + + try: l, dn = s.login_perform(username, oldpassword) + except LoginError, e: + return render(errors = {'oldpassword': str(e)}, username = username) + + import kerberos + try: + assert kerberos.changePassword(username + '@SUBLAB.ORG', oldpassword, password) == True + except kerberos.PwdChangeError, e: + return render(errors = {'password2': str(e.message)}, username = username) + + return s.selectpage(l, dn, + '''Your password has been changed -- + please note that it may take up to 10 minutes for Kerberos to update + its three heads. At any moment, either your old password or your new + password will work.''') + @cherrypy.expose def kill(s): import sys diff --git a/static/app_password.png b/static/app_password.png new file mode 100644 index 0000000..f498440 Binary files /dev/null and b/static/app_password.png differ diff --git a/static/info.png b/static/info.png new file mode 100644 index 0000000..0bcc358 Binary files /dev/null and b/static/info.png differ diff --git a/static/layout.css b/static/layout.css index eb670f5..1b8f0f5 100644 --- a/static/layout.css +++ b/static/layout.css @@ -61,6 +61,24 @@ div#creatpw { input[type=submit] { margin-top:1em; } + +div#infobox { + display:inline-block; + max-width:40em; + color:#000; + background-color:#dde2ff; + border:1px solid #bcf; + margin:2em 0em -1em 0em; +} +div#infobox img { + float:left; + margin:15px 5px; +} +div#infobox p { + text-align:left; + margin-left:45px; +} + body#error img { float:left; margin:2em; diff --git a/templates/layout.xi b/templates/layout.xi index 7b59619..e14e21b 100644 --- a/templates/layout.xi +++ b/templates/layout.xi @@ -14,8 +14,16 @@ + +
+ info +

${select('text()')}

+
+
+ + ${select('sub:infobox')}
${select('*')} diff --git a/templates/pwchange.html b/templates/pwchange.html new file mode 100644 index 0000000..a7e0605 --- /dev/null +++ b/templates/pwchange.html @@ -0,0 +1,23 @@ + + + + + change password + + +
+
uid:
+ ${errors.username} +
old password:
+ ${errors.oldpassword} +
password:
+ ${errors.password} +
repeat:
+ ${errors.password2} + +
+
+ diff --git a/templates/select.html b/templates/select.html index 8b5e47f..1391431 100644 --- a/templates/select.html +++ b/templates/select.html @@ -8,11 +8,14 @@ login + + ${message} + -- cgit v1.2.1