summaryrefslogtreecommitdiff
path: root/users
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-02-28 10:56:38 -0800
committerjessib <jessib@riseup.net>2013-02-28 10:56:38 -0800
commit2d59c67f5991e31c2acd829afffc43fc47d5c474 (patch)
treedd38495d201ed4c36f5421316d7e235bb0eee73d /users
parentf053c1c53f00962ee9ca25d591d248e7695e6fa5 (diff)
parent26bce716526bfc6a59ffbc372d34215ce2242bfe (diff)
Merge pull request #34 from leapcode/feature/limit_usernames
Feature/limit usernames to specific formats, and give specific error messages
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 e41c2dc..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-Za-z\d_\.]+\z/,
- :message => "Only letters, digits, . and _ allowed" }
+ :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