summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorequinox <equinox@diac24.net>2011-09-27 01:13:46 +0200
committerequinox <equinox@diac24.net>2011-09-27 01:14:06 +0200
commit628b4ee18af872ba51e8f07a5b5d2854b1721b2e (patch)
tree820241efc9c8d13d910f3a621f5d7b946759a0b8
parentab8912a8e03150ced5bb2d7bb19d02208b7747d4 (diff)
python: use HTTP method; separate param validation
-rwxr-xr-xindex.py16
-rw-r--r--templates/create.html2
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 += '<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>