diff options
author | Azul <azul@leap.se> | 2012-11-13 12:00:13 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2012-11-13 12:00:13 +0100 |
commit | 6ba3366f778340ebeaa73fd53372368b16de6c98 (patch) | |
tree | 8249f6cd14e1ba859fd63a35f9f24456cb307d13 /users/app | |
parent | 78475cb1b3d4f18a5c0a0fb326e6465b92a5f0e7 (diff) |
using client side validations during signup
Diffstat (limited to 'users/app')
-rw-r--r-- | users/app/assets/javascripts/users.js.coffee | 11 | ||||
-rw-r--r-- | users/app/models/user.rb | 11 | ||||
-rw-r--r-- | users/app/views/users/new.html.haml | 2 |
3 files changed, 13 insertions, 11 deletions
diff --git a/users/app/assets/javascripts/users.js.coffee b/users/app/assets/javascripts/users.js.coffee index 8a9f0e9..ab437f6 100644 --- a/users/app/assets/javascripts/users.js.coffee +++ b/users/app/assets/javascripts/users.js.coffee @@ -1,8 +1,3 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ -# - preventDefault = (event) -> event.preventDefault() @@ -11,9 +6,9 @@ validOrAbort = (event) -> abortIfErrors = -> return if $.isEmptyObject(errors) - $.each errors, (field, error) -> - alert(error) - $('#srp_password').focus() + # we're relying on client_side_validations here instead of printing + # our own errors. This gets us translatable error messages. + $('.control-group.error input, .control-group.error select, control-group.error textarea').first().focus() event.stopImmediatePropagation() validatePassword = -> diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 0f5d650..824c439 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -16,8 +16,11 @@ class User < CouchRest::Model::Base :message => "Only letters, digits and _ allowed" } validates :password_salt, :password_verifier, - :format => { :with => /\A[\dA-Fa-f]+\z/, - :message => "Only hex numbers allowed" } + :format => { :with => /\A[\dA-Fa-f]+\z/, :message => "Only hex numbers allowed" } + + validates :password, :presence => true, + :confirmation => true, + :format => { :with => /.{8}.*/, :message => "needs to be at least 8 characters long" } timestamps! @@ -71,4 +74,8 @@ class User < CouchRest::Model::Base APP_CONFIG['admins'].include? self.login end + protected + def password + password_verifier + end end diff --git a/users/app/views/users/new.html.haml b/users/app/views/users/new.html.haml index 3e7d06d..be14c52 100644 --- a/users/app/views/users/new.html.haml +++ b/users/app/views/users/new.html.haml @@ -3,7 +3,7 @@ = 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 } + = f.input :password, :required => true, :validate => true, :input_html => { :id => :srp_password } = f.input :password_confirmation, :required => true, :input_html => { :id => :srp_password_confirmation } = f.button :submit, :value => t(:signup), :class => 'btn-primary' = link_to t(:cancel), root_url, :class => :btn |