summaryrefslogtreecommitdiff
path: root/users/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'users/app/models')
-rw-r--r--users/app/models/local_email.rb11
-rw-r--r--users/app/models/user.rb2
2 files changed, 12 insertions, 1 deletions
diff --git a/users/app/models/local_email.rb b/users/app/models/local_email.rb
new file mode 100644
index 0000000..5762a33
--- /dev/null
+++ b/users/app/models/local_email.rb
@@ -0,0 +1,11 @@
+class LocalEmail < Email
+
+ validate :unique_on_server
+
+ def unique_on_server
+ 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
+end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index 7d1691a..e5e388b 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -6,7 +6,7 @@ class User < CouchRest::Model::Base
property :email, String, :accessible => true
property :email_forward, String, :accessible => true
- property :email_aliases, [Email]
+ property :email_aliases, [LocalEmail]
validates :login, :password_salt, :password_verifier,
:presence => true