summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--users/app/assets/javascripts/users.js.coffee11
-rw-r--r--users/app/models/user.rb11
-rw-r--r--users/app/views/users/new.html.haml2
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