From aa84a06bf96eb1fd5073263ee5955a62c61b9dc8 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 20 Dec 2012 12:47:31 +0100 Subject: validating email domain and displaying it as the placeholder This even works client side. :) --- users/app/models/local_email.rb | 9 +++++++++ 1 file changed, 9 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 c654fcb..c35fdf7 100644 --- a/users/app/models/local_email.rb +++ b/users/app/models/local_email.rb @@ -3,12 +3,18 @@ class LocalEmail < Email validate :unique_on_server validate :unique_alias_for_user validate :differs_from_main_email + before_validation :add_domain_if_needed + validates :email, + :format => { :with => /@#{APP_CONFIG[:domain]}\Z/, + :message => "needs to end in @#{APP_CONFIG[:domain]}"} validates :casted_by, :presence => true def to_partial_path "emails/email" end + protected + def unique_on_server has_email = User.find_by_email_or_alias(email) if has_email && has_email != self.base_doc @@ -30,5 +36,8 @@ class LocalEmail < Email end end + def add_domain_if_needed + self.email = self.email + "@" + APP_CONFIG[:domain] unless self.email.include?("@") + end end -- cgit v1.2.3