mirror of
https://github.com/internetee/registry.git
synced 2025-06-09 22:24:47 +02:00
35 lines
998 B
Ruby
35 lines
998 B
Ruby
module Concerns
|
|
module EmailCheckable
|
|
extend ActiveSupport::Concern
|
|
|
|
def email_verification
|
|
EmailAddressVerification.find_or_create_by(email: email,
|
|
domain: domain(email))
|
|
end
|
|
|
|
def billing_email_verification
|
|
return unless attribute_names.include?('billing_email')
|
|
|
|
EmailAddressVerification.find_or_create_by(email: billing_email,
|
|
domain: domain(email))
|
|
end
|
|
|
|
def domain(email)
|
|
Mail::Address.new(email).domain || 'not_found'
|
|
rescue Mail::Field::IncompleteParseError
|
|
'not_found'
|
|
end
|
|
|
|
def verify_email_mx_smtp(field:, email:)
|
|
errors.add(field, :invalid) unless email.blank? || Truemail.valid?(email)
|
|
end
|
|
|
|
def correct_email_format
|
|
verify_email_mx_smtp(field: :email, email: email)
|
|
end
|
|
|
|
def correct_billing_email_format
|
|
verify_email_mx_smtp(field: :billing_email, email: billing_email)
|
|
end
|
|
end
|
|
end
|