diff --git a/app/models/concerns/email_checkable.rb b/app/models/concerns/email_checkable.rb new file mode 100644 index 000000000..193352d74 --- /dev/null +++ b/app/models/concerns/email_checkable.rb @@ -0,0 +1,19 @@ +module Concerns + module EmailCheckable + extend ActiveSupport::Concern + + 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 + return if self[:billing_email].blank? + + verify_email_mx_smtp(field: :billing_email, email: billing_email) + end + end +end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 2e2051542..6e6d41b77 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -1,6 +1,7 @@ class Registrar < ApplicationRecord include Versions # version/registrar_version.rb include Concerns::Registrar::BookKeeping + include Concerns::EmailCheckable include Concerns::Registrar::LegalDoc has_many :domains, dependent: :restrict_with_error @@ -193,18 +194,4 @@ class Registrar < ApplicationRecord def vat_liable_in_foreign_country? !vat_liable_locally? 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 - return if self[:billing_email].blank? - - verify_email_mx_smtp(field: :billing_email, email: billing_email) - end end