summaryrefslogtreecommitdiff
path: root/users
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2013-02-28 10:36:24 -0800
committerjessib <jessib@leap.se>2013-02-28 10:36:24 -0800
commit26bce716526bfc6a59ffbc372d34215ce2242bfe (patch)
treef525dae21dc732eaaa179268d99817a9f8bea757 /users
parentc97f356ae8ce07dab04b81d0d0160f3e5fd96f6d (diff)
Have specific error messages for usernames with incorrect formats.
Signed-off-by: jessib <jessib@leap.se>
Diffstat (limited to 'users')
-rw-r--r--users/app/models/user.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index b6e2bad..c9b367f 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -18,9 +18,19 @@ class User < CouchRest::Model::Base
:uniqueness => true,
:if => :serverside?
+ # Have multiple regular expression validations so we can get specific error messages:
validates :login,
- :format => { :with => /\A[a-z][a-z\d_\.-]*[a-z\d]\z/,
- :message => "Only lowercase letters, digits, . - and _ allowed. Login must have at least 2 characters, and begin with a letter, and end with a letter or digit" }
+ :format => { :with => /\A.{2,}\z/,
+ :message => "Login must have at least two characters"}
+ validates :login,
+ :format => { :with => /\A[a-z\d_\.-]+\z/,
+ :message => "Only lowercase letters, digits, . - and _ allowed."}
+ validates :login,
+ :format => { :with => /\A[a-z].*\z/,
+ :message => "Login must begin with a lowercase letter"}
+ validates :login,
+ :format => { :with => /\A.*[a-z\d]\z/,
+ :message => "Login must end with a letter or digit"}
validate :login_is_unique_alias