Revert "297 email address validation truemail"

This commit is contained in:
Timo Võhmar 2020-07-10 16:16:00 +03:00 committed by GitHub
parent 1094c41fa3
commit 6900ce1127
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 158 additions and 964 deletions

View file

@ -1,89 +0,0 @@
module Concerns
module EmailVerifable
extend ActiveSupport::Concern
def email_verification
@email_verification ||= EmailAddressVerification.find_or_create_by(email: unicode_email,
domain: domain(email))
end
def billing_email_verification
return unless attribute_names.include?('billing_email')
@billing_email_verification ||= EmailAddressVerification
.find_or_create_by(email: unicode_billing_email,
domain: domain(billing_email))
end
class_methods do
def domain(email)
Mail::Address.new(email).domain&.downcase || 'not_found'
rescue Mail::Field::IncompleteParseError
'not_found'
end
def local(email)
Mail::Address.new(email).local&.downcase || email
rescue Mail::Field::IncompleteParseError
email
end
def punycode_to_unicode(email)
return email if domain(email) == 'not_found'
local = local(email)
domain = SimpleIDN.to_unicode(domain(email))
"#{local}@#{domain}"&.downcase
end
def unicode_to_punycode(email)
return email if domain(email) == 'not_found'
local = local(email)
domain = SimpleIDN.to_ascii(domain(email))
"#{local}@#{domain}"&.downcase
end
end
def unicode_billing_email
self.class.punycode_to_unicode(billing_email)
end
def unicode_email
self.class.punycode_to_unicode(email)
end
def domain(email)
SimpleIDN.to_unicode(self.class.domain(email))
end
def punycode_to_unicode(email)
self.class.punycode_to_unicode(email)
end
def correct_email_format
return if email.blank?
result = email_verification.verify
process_result(result: result, field: :email)
end
def correct_billing_email_format
return if email.blank?
result = billing_email_verification.verify
process_result(result: result, field: :billing_email)
end
def process_result(result:, field:)
case result[:errors].keys.first
when :smtp
errors.add(field, I18n.t('email_verifable.email_smtp_check_error'))
when :mx
errors.add(field, I18n.t('email_verifable.email_mx_check_error'))
when :regex
errors.add(field, I18n.t('email_verifable.email_regex_check_error'))
end
end
end
end

View file

@ -7,7 +7,6 @@ class Contact < ApplicationRecord
include Concerns::Contact::Transferable
include Concerns::Contact::Identical
include Concerns::Contact::Disclosable
include Concerns::EmailVerifable
belongs_to :original, class_name: self.name
belongs_to :registrar, required: true
@ -23,11 +22,6 @@ class Contact < ApplicationRecord
accepts_nested_attributes_for :legal_documents
scope :email_verification_failed, lambda {
joins('LEFT JOIN email_address_verifications emv ON contacts.email = emv.email')
.where('success = false and verified_at IS NOT NULL')
}
validates :name, :email, presence: true
validates :street, :city, :zip, :country_code, presence: true, if: lambda {
self.class.address_processing?
@ -35,7 +29,8 @@ class Contact < ApplicationRecord
validates :phone, presence: true, e164: true, phone: true
validate :correct_email_format, if: proc { |c| c.will_save_change_to_email? }
validates :email, format: /@/
validates :email, email_format: { message: :invalid }, if: proc { |c| c.will_save_change_to_email? }
validates :code,
uniqueness: { message: :epp_id_taken },

View file

@ -1,56 +0,0 @@
class EmailAddressVerification < ApplicationRecord
RECENTLY_VERIFIED_PERIOD = 1.month
scope :not_verified_recently, lambda {
where('verified_at IS NULL or verified_at < ?', verification_period)
}
scope :verified_recently, lambda {
where('verified_at IS NOT NULL and verified_at >= ?', verification_period).where(success: true)
}
scope :verification_failed, lambda {
where.not(verified_at: nil).where(success: false)
}
scope :by_domain, ->(domain_name) { where(domain: domain_name) }
def recently_verified?
verified_at.present? &&
verified_at > verification_period
end
def verification_period
self.class.verification_period
end
def self.verification_period
Time.zone.now - RECENTLY_VERIFIED_PERIOD
end
def not_verified?
verified_at.blank? && !success
end
def failed?
verified_at.present? && !success
end
def verified?
success
end
def verify
validation_request = Truemail.validate(email)
if validation_request.result.success
update(verified_at: Time.zone.now,
success: true)
else
update(verified_at: Time.zone.now,
success: false)
end
validation_request.result
end
end

View file

@ -88,7 +88,7 @@ class Nameserver < ApplicationRecord
end
def normalize_attributes
self.hostname = hostname.try(:strip).try(:downcase).gsub(/\.$/, '')
self.hostname = hostname.try(:strip).try(:downcase)
self.ipv4 = Array(ipv4).reject(&:blank?).map(&:strip)
self.ipv6 = Array(ipv6).reject(&:blank?).map(&:strip).map(&:upcase)
end

View file

@ -1,7 +1,6 @@
class Registrar < ApplicationRecord
include Versions # version/registrar_version.rb
include Concerns::Registrar::BookKeeping
include Concerns::EmailVerifable
include Concerns::Registrar::LegalDoc
has_many :domains, dependent: :restrict_with_error
@ -30,11 +29,14 @@ class Registrar < ApplicationRecord
validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than: 100 },
allow_nil: true
validate :forbid_special_code
attribute :vat_rate, ::Type::VATRate.new
after_initialize :set_defaults
validate :correct_email_format, if: proc { |c| c.will_save_change_to_email? }
validate :correct_billing_email_format
validates :email, email_format: { message: :invalid },
allow_blank: true, if: proc { |c| c.will_save_change_to_email? }
validates :billing_email, email_format: { message: :invalid }, allow_blank: true
alias_attribute :contact_email, :email