diff options
author | equinox <equinox@diac24.net> | 2011-09-27 01:13:46 +0200 |
---|---|---|
committer | equinox <equinox@diac24.net> | 2011-09-27 01:14:06 +0200 |
commit | 628b4ee18af872ba51e8f07a5b5d2854b1721b2e (patch) | |
tree | 820241efc9c8d13d910f3a621f5d7b946759a0b8 | |
parent | ab8912a8e03150ced5bb2d7bb19d02208b7747d4 (diff) |
python: use HTTP method; separate param validation
-rwxr-xr-x | index.py | 16 | ||||
-rw-r--r-- | templates/create.html | 2 |
2 files changed, 12 insertions, 6 deletions
@@ -81,11 +81,7 @@ class SubdapSite(object): # details.append([k, value]) ## x += '<tr><td>%s</td><td><pre>%s</pre></td></tr>\n' % (k, "<hr>".join(v)) - @expose('create.html') - def create(s): - return render(errors = {}, username = '') - @expose('create.html') - def docreate(s, username = None, password = None, password2 = None): + def params_validate(s, errors, username, password, password2): errors = {} if username == None or username == '': errors['username'] = 'please specify an user name' @@ -96,6 +92,16 @@ class SubdapSite(object): if password2 != password: errors['password2'] = 'passwords did not match' if len(errors) > 0: + return errors + return None + + @expose('create.html') + def create(s, username = None, password = None, password2 = None): + if cherrypy.request.method.upper() == 'GET': + return render(errors = {}, username = '') + + errors = s.params_validate(errors, username, password, password2) + if errors is not None: return render(errors = errors, username = username) accountservice.name_create(username, password) diff --git a/templates/create.html b/templates/create.html index fbf1323..eb2bdc1 100644 --- a/templates/create.html +++ b/templates/create.html @@ -9,7 +9,7 @@ <title>create</title> </head> <sub:bodyform> - <form action='docreate' method='POST'> + <form action='create' method='POST'> <div>uid: <input type='text' name='username' size="10" value="${username}"/></div> <b class="error" py:if="'username' in errors">${errors.username}</b> <div id="creatpw">password: <input type='password' name='password' size="10" value=""/></div> |