Add email & nonverified color to contact show

This commit is contained in:
Alex Sherman 2020-06-09 14:05:52 +05:00
parent 3d444c3a04
commit 48036c660d
5 changed files with 10 additions and 5 deletions

View file

@ -0,0 +1,35 @@
module Concerns
module EmailVerifable
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