summaryrefslogtreecommitdiff
path: root/users/app
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-13 11:49:26 +0100
committerAzul <azul@leap.se>2012-12-13 11:49:55 +0100
commitd7890d7c8af6691df2817a9b6654acf9377847bd (patch)
treec66372f4d25a34028b8873fb652761e8f4a1ec02 /users/app
parent60e8fc3e1309d1c972a7695e3344e63f5d633a06 (diff)
LocalEmail added - will validate uniqueness amongst emails and aliases
Diffstat (limited to 'users/app')
-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