mirror of
https://github.com/internetee/registry.git
synced 2025-06-09 14:14:49 +02:00
Fix CC issues
This commit is contained in:
parent
a13725faa7
commit
3d444c3a04
5 changed files with 27 additions and 14 deletions
|
@ -1,5 +1,4 @@
|
||||||
class VerifyEmailsJob < Que::Job
|
class VerifyEmailsJob < Que::Job
|
||||||
|
|
||||||
def run(verification_id)
|
def run(verification_id)
|
||||||
email_address_verification = run_condition(EmailAddressVerification.find(verification_id))
|
email_address_verification = run_condition(EmailAddressVerification.find(verification_id))
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,21 @@ module Concerns
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
def email_verification
|
def email_verification
|
||||||
EmailAddressVerification.find_or_create_by(email: self.email,
|
EmailAddressVerification.find_or_create_by(email: email,
|
||||||
domain: Mail::Address.new(self.email).domain)
|
domain: domain(email))
|
||||||
end
|
end
|
||||||
|
|
||||||
def billing_email_verification
|
def billing_email_verification
|
||||||
if self.attribute_names.include?('billing_email')
|
return unless attribute_names.include?('billing_email')
|
||||||
EmailAddressVerification.find_or_create_by(email: self.billing_email,
|
|
||||||
domain: Mail::Address.new(self.email).domain)
|
EmailAddressVerification.find_or_create_by(email: billing_email,
|
||||||
else
|
domain: domain(email))
|
||||||
nil
|
end
|
||||||
end
|
|
||||||
|
def domain(email)
|
||||||
|
Mail::Address.new(email).domain || 'not_found'
|
||||||
|
rescue Mail::Field::IncompleteParseError
|
||||||
|
'not_found'
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_email_mx_smtp(field:, email:)
|
def verify_email_mx_smtp(field:, email:)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
class EmailAddressVerification < ApplicationRecord
|
class EmailAddressVerification < ApplicationRecord
|
||||||
RECENTLY_VERIFIED_PERIOD = 1.month
|
RECENTLY_VERIFIED_PERIOD = 1.month
|
||||||
|
|
||||||
scope :not_verified_recently, -> {
|
scope :not_verified_recently, lambda {
|
||||||
where('verified_at IS NULL or verified_at < ?', verification_period)
|
where('verified_at IS NULL or verified_at < ?', verification_period)
|
||||||
}
|
}
|
||||||
|
|
||||||
scope :verified_recently, -> {
|
scope :verified_recently, lambda {
|
||||||
where('verified_at IS NOT NULL and verified_at >= ?', verification_period)
|
where('verified_at IS NOT NULL and verified_at >= ?', verification_period)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,8 @@ class EmailAddressVerification < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify
|
def verify
|
||||||
media = success ? :mx : :smtp
|
# media = success ? :mx : :smtp
|
||||||
|
media = :mx
|
||||||
validation_request = Truemail.validate(email, with: media)
|
validation_request = Truemail.validate(email, with: media)
|
||||||
|
|
||||||
if validation_request.result.success
|
if validation_request.result.success
|
||||||
|
|
|
@ -7,7 +7,7 @@ class FillEmailVerifications < ActiveRecord::Migration[6.0]
|
||||||
emails = (contact_emails || registrar_emails || registrar_billing_emails).uniq
|
emails = (contact_emails || registrar_emails || registrar_billing_emails).uniq
|
||||||
|
|
||||||
result = emails.map do |email|
|
result = emails.map do |email|
|
||||||
{ email: email, domain: Mail::Address.new(email).domain || 'not_found' }
|
{ email: email, domain: domain(email) }
|
||||||
end
|
end
|
||||||
|
|
||||||
EmailAddressVerification.import result, batch_size: 500
|
EmailAddressVerification.import result, batch_size: 500
|
||||||
|
@ -16,4 +16,10 @@ class FillEmailVerifications < ActiveRecord::Migration[6.0]
|
||||||
def down
|
def down
|
||||||
EmailAddressVerification.delete_all
|
EmailAddressVerification.delete_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def domain(email)
|
||||||
|
Mail::Address.new(email).domain || 'not_found'
|
||||||
|
rescue Mail::Field::IncompleteParseError
|
||||||
|
'not_found'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,9 +3,12 @@ namespace :verify_email do
|
||||||
task all_domains: :environment do
|
task all_domains: :environment do
|
||||||
verifications_by_domain = EmailAddressVerification.not_verified_recently.group_by(&:domain)
|
verifications_by_domain = EmailAddressVerification.not_verified_recently.group_by(&:domain)
|
||||||
|
|
||||||
verifications_by_domain.each do |_domain, verifications|
|
verifications_by_domain.each do |domain, verifications|
|
||||||
|
next if domain == 'not_found'
|
||||||
|
|
||||||
ver = verifications[0] # Only first email to not to clog the SMTP servers
|
ver = verifications[0] # Only first email to not to clog the SMTP servers
|
||||||
VerifyEmailsJob.enqueue(ver.id)
|
VerifyEmailsJob.enqueue(ver.id)
|
||||||
|
# VerifyEmailsJob.run(ver.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue