diff options
author | Azul <azul@leap.se> | 2013-01-17 16:28:52 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2013-01-17 16:28:52 +0100 |
commit | 247a6f14db14543773beb1a1e96f2c335800eb82 (patch) | |
tree | 5cf0740eb4ffd3ec836c146ef6ab2fd2955ca4fb /users/app/models | |
parent | a8ec73a0307924610023525786bb3a9eb8b173e1 (diff) |
minor fixes to validation workflow
Diffstat (limited to 'users/app/models')
-rw-r--r-- | users/app/models/local_email.rb | 11 | ||||
-rw-r--r-- | users/app/models/user.rb | 2 |
2 files changed, 5 insertions, 8 deletions
diff --git a/users/app/models/local_email.rb b/users/app/models/local_email.rb index 587acc6..bd9dea3 100644 --- a/users/app/models/local_email.rb +++ b/users/app/models/local_email.rb @@ -7,16 +7,13 @@ class LocalEmail before_validation :strip_domain_if_needed validates :username, - :format => { :with => /\A([^@\s]+)(@.*)?\Z/, :message => "needs to be a valid login or email address"} + :presence => true, + :format => { :with => /\A([^@\s]+)(@#{APP_CONFIG[:domain]})?\Z/i, :message => "needs to be a valid login or email address @#{APP_CONFIG[:domain]}"} validate :unique_on_server validate :unique_alias_for_user validate :differs_from_login - validates :username, - :presence => true, - :format => { :with => /[^@]*(@#{APP_CONFIG[:domain]})?\Z/i, - :message => "may not contain an '@' or needs to end in @#{APP_CONFIG[:domain]}"} validates :casted_by, :presence => true def email @@ -38,7 +35,7 @@ class LocalEmail def unique_on_server has_email = User.find_by_login_or_alias(username) - if has_email && has_email != self.base_doc + if has_email && has_email != self.casted_by errors.add :username, "has already been taken" end end @@ -60,7 +57,7 @@ class LocalEmail end def strip_domain_if_needed - self.username.gsub /@#{APP_CONFIG[:domain]}/i, '' + self.username.gsub! /@#{APP_CONFIG[:domain]}/i, '' end end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index f89d01c..63f4d0f 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -72,7 +72,7 @@ class User < CouchRest::Model::Base end def email_address - login + '@' + APP_CONFIG[:domain] + LocalEmail.new(login) end # Since we are storing admins by login, we cannot allow admins to change their login. |