diff options
author | azul <azul@riseup.net> | 2012-12-20 01:53:32 -0800 |
---|---|---|
committer | azul <azul@riseup.net> | 2012-12-20 01:53:32 -0800 |
commit | 69a6c34998328b2168053184e1e487b60e1cc536 (patch) | |
tree | 361b0be19535b0d7ddb3eaac7acdfcebc7a0e3a8 /users/app/models/local_email.rb | |
parent | e899e5c3f33acb3228fac295013d7cc8b6e4eb04 (diff) | |
parent | dc827d0a80360aa245d4d724dc42bc47571faea6 (diff) |
Merge pull request #5 from leapcode/feature/removing-email-aliases
Removing email aliases - proper error display
Diffstat (limited to 'users/app/models/local_email.rb')
-rw-r--r-- | users/app/models/local_email.rb | 21 |
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 |