From cc96c60c4617c09379d5e1ddbefa42407329c19a Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 18 Jul 2013 12:12:07 +0200 Subject: testing all versions of emial identities, emails are now strings --- users/app/models/local_email.rb | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (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 69cba01..1cadc71 100644 --- a/users/app/models/local_email.rb +++ b/users/app/models/local_email.rb @@ -1,25 +1,11 @@ -class LocalEmail - include CouchRest::Model::Embeddable - include Email - - property :username, String - - before_validation :strip_domain_if_needed - - validates :username, - :presence => true, - :format => { :with => /\A([^@\s]+)(@#{APP_CONFIG[:domain]})?\Z/i, :message => "needs to be a valid login or email address @#{APP_CONFIG[:domain]}"} +class LocalEmail < Email +=begin validate :unique_on_server validate :unique_alias_for_user validate :differs_from_login +=end - validates :casted_by, :presence => true - - def email - return '' if username.nil? - username + '@' + APP_CONFIG[:domain] - end def email=(value) return if value.blank? -- cgit v1.2.3 From a2e49d1b946fa34dd41ce1f07920515df13e09db Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 18 Jul 2013 12:28:51 +0200 Subject: local email adds domain if needed --- users/app/models/local_email.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (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 1cadc71..d919102 100644 --- a/users/app/models/local_email.rb +++ b/users/app/models/local_email.rb @@ -6,15 +6,17 @@ class LocalEmail < Email validate :differs_from_login =end - - def email=(value) - return if value.blank? - self.username = value - strip_domain_if_needed + def initialize(s) + super + append_domain_if_needed end def to_key - [username] + [handle] + end + + def handle + gsub(/@#{APP_CONFIG[:domain]}/i, '') end protected @@ -42,8 +44,10 @@ class LocalEmail < Email end end - def strip_domain_if_needed - self.username.gsub! /@#{APP_CONFIG[:domain]}/i, '' + def append_domain_if_needed + unless self.index('@') + self << "@#{APP_CONFIG[:domain]}" + end end end -- cgit v1.2.3 From d96fac2de074bbe3a44d888af5ceaff45b1b9b27 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 18 Jul 2013 12:52:02 +0200 Subject: validations of email format and local domain moved over --- users/app/models/local_email.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (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 d919102..e71d494 100644 --- a/users/app/models/local_email.rb +++ b/users/app/models/local_email.rb @@ -6,6 +6,18 @@ class LocalEmail < Email validate :differs_from_login =end + def self.domain + APP_CONFIG[:domain] + end + + validates :email, + :format => { + :with => /@#{domain}\Z/i, + :message => "needs to end in @#{domain}" + } + + + def initialize(s) super append_domain_if_needed @@ -16,7 +28,11 @@ class LocalEmail < Email end def handle - gsub(/@#{APP_CONFIG[:domain]}/i, '') + gsub(/@#{domain}/i, '') + end + + def domain + LocalEmail.domain end protected @@ -46,7 +62,7 @@ class LocalEmail < Email def append_domain_if_needed unless self.index('@') - self << "@#{APP_CONFIG[:domain]}" + self << '@' + domain end end -- cgit v1.2.3 From 0acace58c31c96fc1f8836167aeb4f204f72617f Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 18 Jul 2013 17:17:36 +0200 Subject: allow available and unique forwards only --- users/app/models/local_email.rb | 30 ------------------------------ 1 file changed, 30 deletions(-) (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 e71d494..c1f7c11 100644 --- a/users/app/models/local_email.rb +++ b/users/app/models/local_email.rb @@ -1,10 +1,5 @@ class LocalEmail < Email -=begin - validate :unique_on_server - validate :unique_alias_for_user - validate :differs_from_login -=end def self.domain APP_CONFIG[:domain] @@ -16,8 +11,6 @@ class LocalEmail < Email :message => "needs to end in @#{domain}" } - - def initialize(s) super append_domain_if_needed @@ -37,29 +30,6 @@ class LocalEmail < Email protected - def unique_on_server - has_email = User.find_by_login_or_alias(username) - if has_email && has_email != self.casted_by - errors.add :username, "has already been taken" - end - end - - def unique_alias_for_user - aliases = self.casted_by.email_aliases - if aliases.select{|a|a.username == self.username}.count > 1 - errors.add :username, "is already your alias" - end - end - - def differs_from_login - # If this has not changed but the email let's mark the email invalid instead. - return if self.persisted? - user = self.casted_by - if user.login == self.username - errors.add :username, "may not be the same as your email address" - end - end - def append_domain_if_needed unless self.index('@') self << '@' + domain -- cgit v1.2.3