diff options
Diffstat (limited to 'users/app/models')
-rw-r--r-- | users/app/models/local_email.rb | 9 | ||||
-rw-r--r-- | users/app/models/user.rb | 4 |
2 files changed, 13 insertions, 0 deletions
diff --git a/users/app/models/local_email.rb b/users/app/models/local_email.rb index c654fcb..24624e7 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 += "@" + APP_CONFIG[:domain] unless self.email.include?("@") + end end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 1999a28..8f776a3 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -32,6 +32,10 @@ class User < CouchRest::Model::Base validates :email, :format => { :with => /\A(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}))?\Z/, :message => "needs to be a valid email address"} + validates :email, + :format => { :with => /@#{APP_CONFIG[:domain]}\Z/, + :message => "needs to end in @#{APP_CONFIG[:domain]}"} + validates :email_forward, :format => { :with => /\A(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}))?\Z/, :message => "needs to be a valid email address"} |