summaryrefslogtreecommitdiff
path: root/users/app/models/local_email.rb
diff options
context:
space:
mode:
Diffstat (limited to 'users/app/models/local_email.rb')
-rw-r--r--users/app/models/local_email.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/users/app/models/local_email.rb b/users/app/models/local_email.rb
index 7cca4f4..c654fcb 100644
--- a/users/app/models/local_email.rb
+++ b/users/app/models/local_email.rb
@@ -1,6 +1,9 @@
class LocalEmail < Email
validate :unique_on_server
+ validate :unique_alias_for_user
+ validate :differs_from_main_email
+ validates :casted_by, :presence => true
def to_partial_path
"emails/email"
@@ -9,7 +12,23 @@ class LocalEmail < Email
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")
+ errors.add :email, "has already been taken"
end
end
+
+ def unique_alias_for_user
+ aliases = self.casted_by.email_aliases
+ if aliases.select{|a|a.email == self.email}.count > 1
+ errors.add :email, "is already your alias"
+ end
+ end
+
+ def differs_from_main_email
+ user = self.casted_by
+ if user.email == self.email
+ errors.add :email, "may not be the same as your email address"
+ end
+ end
+
+
end