diff --git a/pyjaco/todoy.py b/pyjaco/todoy.py new file mode 100644 index 0000000..c9bf0f9 --- /dev/null +++ b/pyjaco/todoy.py @@ -0,0 +1,25 @@ + +def setup(): + validate("#registration_form", + { + 'confirm_password': 'The passwords do not match', + 'username': "I'm afraid that username is taken"}, + username={ + 'required': True, + 'remote': 'user_valid.json' + }, + password='required', + confirm_password={'equalTo': 'input[name=password]'}) + + +@JSVar('jQuery') +def validate(selector, mess=None, **kwargs): + if mess == None: + mess = {} + jQuery(js(selector)).validate( + {'rules': js(kwargs), + 'messages': js(mess) + } + ) + +jQuery(js(setup)) diff --git a/www/account/register.html b/www/account/register.html index de65d8e..92aa281 100644 --- a/www/account/register.html +++ b/www/account/register.html @@ -1,5 +1,4 @@ # -*- python -*- -import json from aspen import Response from trembling.auth import User from trembling import Redirect @@ -46,7 +45,7 @@ except InvalidDataError as e: print e.error_dict() response = Response(406, json.dumps( - {k:v.message for k,v in e.error_dict().iteritems()})) + {k: v.message for k, v in e.error_dict().iteritems()})) else: print "VALID" diff --git a/www/account/user_valid.json b/www/account/user_valid.json new file mode 100644 index 0000000..8f7c49b --- /dev/null +++ b/www/account/user_valid.json @@ -0,0 +1,15 @@ +# -*- python -*- +# This json response is used by the validator on +# register.html +from aspen import Response +from trembling.auth import User + +^L +username = request.qs.one('username') +existing_user = User.objects(username=username) + +response = Response() +if existing_user: + response.body = False +else: + response.body = True diff --git a/www/js/todoy.js b/www/js/todoy.js index 4bf246e..892e9ab 100644 --- a/www/js/todoy.js +++ b/www/js/todoy.js @@ -2,7 +2,7 @@ var setup = function() { var __kwargs = __kwargs_get(arguments); var __varargs = __varargs_get(arguments); var $v1 = Array.prototype.slice.call(arguments).concat(js(__varargs)); - validate(str('#registration_form'), dict([str('confirm_password'), str('The passwords do not match')]), __kwargs_make({username: str('required'), password: str('required'), confirm_password: dict([str('equalTo'), str('input[name=password]')])})); + validate(str('#registration_form'), dict([str('confirm_password'), str('The passwords do not match'), str('username'), str("I'm afraid that username is taken")]), __kwargs_make({username: dict([str('required'), __builtins__.PY$True, str('remote'), str('user_valid.json')]), password: str('required'), confirm_password: dict([str('equalTo'), str('input[name=password]')])})); return None; } var validate = function() {