mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 23:24:48 +02:00
Move email checks and validation methods to concern
This commit is contained in:
parent
e56162f37d
commit
1b06e43f18
2 changed files with 20 additions and 14 deletions
19
app/models/concerns/email_checkable.rb
Normal file
19
app/models/concerns/email_checkable.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue