diff options
author | jessib <jessib@riseup.net> | 2013-08-22 11:32:31 -0700 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2013-08-22 11:32:31 -0700 |
commit | 8c45a3c54f2b0b709ebf040de0db00b6913e709b (patch) | |
tree | 3474b0db6b7e4921566af430fa36d790ac021dd0 /users/app/models | |
parent | 41de2179c67fc09e1558280c5601cc07b2e40b43 (diff) | |
parent | 75db45671d432a0d81805ad50c6cc9f8f7eff7a7 (diff) |
Merge pull request #70 from azul/bugfix/validate_login_like_signup
use the same login validations on sessions and users
Diffstat (limited to 'users/app/models')
-rw-r--r-- | users/app/models/login_format_validation.rb | 19 | ||||
-rw-r--r-- | users/app/models/session.rb | 6 | ||||
-rw-r--r-- | users/app/models/user.rb | 15 |
3 files changed, 22 insertions, 18 deletions
diff --git a/users/app/models/login_format_validation.rb b/users/app/models/login_format_validation.rb new file mode 100644 index 0000000..1d02bd1 --- /dev/null +++ b/users/app/models/login_format_validation.rb @@ -0,0 +1,19 @@ +module LoginFormatValidation + extend ActiveSupport::Concern + + included do + # Have multiple regular expression validations so we can get specific error messages: + validates :login, + :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"} + end +end diff --git a/users/app/models/session.rb b/users/app/models/session.rb index a9fdb1b..0d7e10e 100644 --- a/users/app/models/session.rb +++ b/users/app/models/session.rb @@ -1,12 +1,10 @@ class Session < SRP::Session include ActiveModel::Validations + include LoginFormatValidation attr_accessor :login - validates :login, - :presence => true, - :format => { :with => /\A[A-Za-z\d_]+\z/, - :message => "Only letters, digits and _ allowed" } + validates :login, :presence => true def initialize(user = nil, aa = nil) super(user, aa) if user diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 0a89f7c..c1988f3 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -1,4 +1,5 @@ class User < CouchRest::Model::Base + include LoginFormatValidation use_database :users @@ -15,20 +16,6 @@ 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.{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 validates :password_salt, :password_verifier, |