summaryrefslogtreecommitdiff
path: root/users/app/models/user.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-20 17:38:36 +0100
committerAzul <azul@leap.se>2012-12-20 17:38:36 +0100
commitc83ada50de6b9a7084a23037068ba7f12e09dfc9 (patch)
tree75c0eef72cb7a2c4e0cfb8350a79631e5c5a8595 /users/app/models/user.rb
parentc4f87b3447ab2a96dc9181d0b89be4f6f025042a (diff)
fixed tests, testing corner cases, fixed these
Diffstat (limited to 'users/app/models/user.rb')
-rw-r--r--users/app/models/user.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index 8f776a3..2a8a57b 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -33,9 +33,11 @@ class User < CouchRest::Model::Base
:format => { :with => /\A(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}))?\Z/, :message => "needs to be a valid email address"}
validates :email,
- :format => { :with => /@#{APP_CONFIG[:domain]}\Z/,
+ :format => { :with => /\A(.+@#{APP_CONFIG[:domain]})?\Z/,
:message => "needs to end in @#{APP_CONFIG[:domain]}"}
+ validate :email_unique_on_server
+
validates :email_forward,
:format => { :with => /\A(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}))?\Z/, :message => "needs to be a valid email address"}
@@ -125,18 +127,28 @@ class User < CouchRest::Model::Base
email_aliases.build(attrs.values.first) if attrs
end
+ protected
+
##
# Validation Functions
##
def email_differs_from_email_aliases
+ # If this has not changed but the email aliases let's not mark this invalid.
return if email_aliases.any? and email_aliases.last.errors.any?
if email_aliases.map(&:email).include?(email)
errors.add(:email, "may not be the same as an alias")
end
end
- protected
+ def email_unique_on_server
+ return unless email
+ has_email = User.find_by_email_or_alias(email)
+ if has_email && has_email != self.base_doc
+ errors.add :email, "has already been taken"
+ end
+ end
+
def password
password_verifier
end