From 628b4ee18af872ba51e8f07a5b5d2854b1721b2e Mon Sep 17 00:00:00 2001 From: equinox Date: Tue, 27 Sep 2011 01:13:46 +0200 Subject: python: use HTTP method; separate param validation --- index.py | 16 +++++++++++----- templates/create.html | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/index.py b/index.py index debb815..eda9043 100755 --- a/index.py +++ b/index.py @@ -81,11 +81,7 @@ class SubdapSite(object): # details.append([k, value]) ## x += '%s
%s
\n' % (k, "
".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 @@ create -
+
uid:
${errors.username}
password:
-- cgit v1.2.1