From 7e5db2a28ba872154e5f5002bb84d149a512e36e Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 22 Nov 2012 10:33:21 +0100 Subject: using the new srp.js api --- users/app/assets/javascripts/srp | 2 +- users/app/assets/javascripts/users.js.coffee | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'users/app/assets/javascripts') diff --git a/users/app/assets/javascripts/srp b/users/app/assets/javascripts/srp index efac662..635ea47 160000 --- a/users/app/assets/javascripts/srp +++ b/users/app/assets/javascripts/srp @@ -1 +1 @@ -Subproject commit efac662cdf31bc4b61ffb97b8c398e22a86c364b +Subproject commit 635ea47f1c19d7985a8f5107c070ae19edf9dd54 diff --git a/users/app/assets/javascripts/users.js.coffee b/users/app/assets/javascripts/users.js.coffee index ab437f6..75440ea 100644 --- a/users/app/assets/javascripts/users.js.coffee +++ b/users/app/assets/javascripts/users.js.coffee @@ -27,21 +27,21 @@ validOrAbort = (event) -> abortIfErrors() -signup = (event) -> - srp = new SRP(jqueryRest()) - srp.register -> - window.location = '/' -login = (event) -> - srp = new SRP(jqueryRest()) - srp.identify -> - window.location = '/' +srp.session = new srp.Session() +srp.signedUp = -> + window.location = '/' +srp.loggedIn = -> + window.location = '/' + +srp.error = (message) -> + alert(message) $(document).ready -> $('#new_user').submit preventDefault $('#new_user').submit validOrAbort - $('#new_user').submit signup + $('#new_user').submit srp.signup $('#new_session').submit preventDefault - $('#new_session').submit login + $('#new_session').submit srp.login -- cgit v1.2.3 From cec9ad7c514f2f3c767bd12bfc3df28db4d1a98b Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 22 Nov 2012 11:36:25 +0100 Subject: using client side validations for login --- users/app/assets/javascripts/users.js.coffee | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'users/app/assets/javascripts') diff --git a/users/app/assets/javascripts/users.js.coffee b/users/app/assets/javascripts/users.js.coffee index 75440ea..6d1dda2 100644 --- a/users/app/assets/javascripts/users.js.coffee +++ b/users/app/assets/javascripts/users.js.coffee @@ -36,7 +36,13 @@ srp.loggedIn = -> window.location = '/' srp.error = (message) -> - alert(message) + if $.isPlainObject(message) && message.errors + for key, value of message.errors + element = $('form input[name="session['+key+']"]') + next unless element + element.trigger('element:validate:fail.ClientSideValidations', value).data('valid', false) + else + alert(message) $(document).ready -> $('#new_user').submit preventDefault -- cgit v1.2.3 From 6d5f8d0f993093b51d1f11bb528c535dcf88a969 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 22 Nov 2012 13:05:32 +0100 Subject: beautify login workflow * translating error messages * not caching login and password in js anymore * catching non responses --- users/app/assets/javascripts/srp | 2 +- users/app/assets/javascripts/users.js.coffee | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'users/app/assets/javascripts') diff --git a/users/app/assets/javascripts/srp b/users/app/assets/javascripts/srp index 635ea47..076d6e2 160000 --- a/users/app/assets/javascripts/srp +++ b/users/app/assets/javascripts/srp @@ -1 +1 @@ -Subproject commit 635ea47f1c19d7985a8f5107c070ae19edf9dd54 +Subproject commit 076d6e251e4caf826787d87b11434e535960455c diff --git a/users/app/assets/javascripts/users.js.coffee b/users/app/assets/javascripts/users.js.coffee index 6d1dda2..d0ec32f 100644 --- a/users/app/assets/javascripts/users.js.coffee +++ b/users/app/assets/javascripts/users.js.coffee @@ -37,10 +37,10 @@ srp.loggedIn = -> srp.error = (message) -> if $.isPlainObject(message) && message.errors - for key, value of message.errors - element = $('form input[name="session['+key+']"]') + for field, error of message.errors + element = $('form input[name="session['+field+']"]') next unless element - element.trigger('element:validate:fail.ClientSideValidations', value).data('valid', false) + element.trigger('element:validate:fail.ClientSideValidations', error).data('valid', false) else alert(message) -- cgit v1.2.3