Return truemail

This reverts commit 862f5639ebbe4d3e6abd5d5be7fb7840e7b83bdf.
This commit is contained in:
Alex Sherman 2020-07-13 15:04:56 +05:00
parent 0a7b754c4c
commit e4a02c2e47
35 changed files with 728 additions and 153 deletions

View file

@ -75,6 +75,7 @@ module Concerns
process_result(result: result, field: :billing_email)
end
# rubocop:disable Metrics/LineLength
def process_result(result:, field:)
case result[:errors].keys.first
when :smtp
@ -85,5 +86,6 @@ module Concerns
errors.add(field, I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'))
end
end
# rubocop:enable Metrics/LineLength
end
end

View file

@ -7,6 +7,7 @@ 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
@ -22,6 +23,11 @@ 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?
@ -29,8 +35,7 @@ class Contact < ApplicationRecord
validates :phone, presence: true, e164: true, phone: true
validates :email, format: /@/
validates :email, email_format: { message: :invalid }, if: proc { |c| c.will_save_change_to_email? }
validate :correct_email_format, if: proc { |c| c.will_save_change_to_email? }
validates :code,
uniqueness: { message: :epp_id_taken },

View file

@ -0,0 +1,56 @@
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

@ -60,6 +60,7 @@ class Epp::Contact < Contact
delegate :ident_attr_valid?, to: :class
# rubocop:disable Style/SymbolArray
def epp_code_map
{
'2003' => [ # Required parameter missing
@ -80,7 +81,7 @@ class Epp::Contact < Contact
[:code, :too_long_contact_code],
[:email, :email_smtp_check_error],
[:email, :email_mx_check_error],
[:email, :email_regex_check_error]
[:email, :email_regex_check_error],
],
'2302' => [ # Object exists
[:code, :epp_id_taken]
@ -90,6 +91,7 @@ class Epp::Contact < Contact
]
}
end
# rubocop:enable Style/SymbolArray
def attach_legal_document(legal_document_data)
return unless legal_document_data

View file

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

View file

@ -1,6 +1,7 @@
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
@ -29,14 +30,11 @@ 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
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
validate :correct_email_format, if: proc { |c| c.will_save_change_to_email? }
validate :correct_billing_email_format
alias_attribute :contact_email, :email