From d7890d7c8af6691df2817a9b6654acf9377847bd Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 13 Dec 2012 11:49:26 +0100 Subject: LocalEmail added - will validate uniqueness amongst emails and aliases --- users/app/models/local_email.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 users/app/models/local_email.rb (limited to 'users/app/models/local_email.rb') 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 -- cgit v1.2.3 From feee17e3a9970ac04f5a789255fbf4c3e8e89eb8 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 13 Dec 2012 17:15:14 +0100 Subject: use the same partial for Email and LocalEmail --- users/app/models/local_email.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'users/app/models/local_email.rb') diff --git a/users/app/models/local_email.rb b/users/app/models/local_email.rb index 5762a33..7cca4f4 100644 --- a/users/app/models/local_email.rb +++ b/users/app/models/local_email.rb @@ -2,6 +2,10 @@ class LocalEmail < Email validate :unique_on_server + def to_partial_path + "emails/email" + end + def unique_on_server has_email = User.find_by_email_or_alias(email) if has_email && has_email != self.base_doc -- cgit v1.2.3