Add data migration to fill EmailAddressVerifications

This commit is contained in:
Alex Sherman 2020-06-08 14:12:39 +05:00
parent 9758c82221
commit ee7d69c1ce
4 changed files with 29 additions and 160 deletions

View file

@ -3,12 +3,14 @@ module Concerns
extend ActiveSupport::Concern
def email_verification
EmailAddressVerification.find_or_create_by(email: self.email)
EmailAddressVerification.find_or_create_by(email: self.email,
domain: Mail::Address.new(self.email).domain)
end
def billing_email_verification
if self.attribute_names.include?('billing_email')
EmailAddressVerification.find_or_create_by(email: self.billing_email)
EmailAddressVerification.find_or_create_by(email: self.billing_email,
domain: Mail::Address.new(self.email).domain)
else
nil
end
@ -23,8 +25,6 @@ module Concerns
end
def correct_billing_email_format
return if self[:billing_email].blank?
verify_email_mx_smtp(field: :billing_email, email: billing_email)
end
end

View file

@ -10,6 +10,11 @@ class EmailAddressVerification < ApplicationRecord
def verify
validation_request = Truemail.validate(email)
update(verified_at: Time.zone.now) if validation_request.result.success
if validation_request.result.success
update(verified_at: Time.zone.now,
success: true)
end
validation_request.result.success
end
end