summaryrefslogtreecommitdiff
path: root/users
diff options
context:
space:
mode:
Diffstat (limited to 'users')
-rw-r--r--users/app/assets/javascripts/users.js.coffee51
-rw-r--r--users/app/views/users/new.html.haml2
2 files changed, 30 insertions, 23 deletions
diff --git a/users/app/assets/javascripts/users.js.coffee b/users/app/assets/javascripts/users.js.coffee
index 24302fe..8a9f0e9 100644
--- a/users/app/assets/javascripts/users.js.coffee
+++ b/users/app/assets/javascripts/users.js.coffee
@@ -3,43 +3,50 @@
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
#
-validate_password = (event) ->
+preventDefault = (event) ->
+ event.preventDefault()
- password = $('#srp_password').val()
- confirmation = $('#srp_password_confirmation').val()
- login = $('#srp_username').val()
-
- if password != confirmation
- alert "Password and Confirmation do not match!"
- $('#srp_password').focus()
- return false
- if password == login
- alert "Password and Login may not match!"
- $('#srp_password').focus()
- return false
- if password.length < 8
- alert "Password needs to be at least 8 characters long!"
- $('#srp_password').focus()
- return false
+validOrAbort = (event) ->
+ errors = {}
+
+ abortIfErrors = ->
+ return if $.isEmptyObject(errors)
+ $.each errors, (field, error) ->
+ alert(error)
+ $('#srp_password').focus()
+ event.stopImmediatePropagation()
+
+ validatePassword = ->
+ password = $('#srp_password').val()
+ confirmation = $('#srp_password_confirmation').val()
+ login = $('#srp_username').val()
+
+ if password != confirmation
+ errors.password_confirmation = "Confirmation does not match!"
+ if password == login
+ errors.password = "Password and Login may not match!"
+ if password.length < 8
+ errors.password = "Password needs to be at least 8 characters long!"
+
+ validatePassword()
+ abortIfErrors()
- return true
-
signup = (event) ->
srp = new SRP(jqueryRest())
srp.register ->
window.location = '/'
- false
login = (event) ->
srp = new SRP(jqueryRest())
srp.identify ->
window.location = '/'
- false
$(document).ready ->
- $('#new_user').submit validate_password
+ $('#new_user').submit preventDefault
+ $('#new_user').submit validOrAbort
$('#new_user').submit signup
+ $('#new_session').submit preventDefault
$('#new_session').submit login
diff --git a/users/app/views/users/new.html.haml b/users/app/views/users/new.html.haml
index 835e99a..3e7d06d 100644
--- a/users/app/views/users/new.html.haml
+++ b/users/app/views/users/new.html.haml
@@ -1,6 +1,6 @@
.span8.offset2
%h2=t :signup
- = simple_form_for @user, :html => {:class => 'form-horizontal'} do |f|
+ = simple_form_for @user, :validate => true, :html => {:class => 'form-horizontal'} do |f|
%legend=t :signup_message
= f.input :login, :input_html => { :id => :srp_username }
= f.input :password, :required => true, :input_html => { :id => :srp_password }