diff --git a/app/controllers/admin/contacts_controller.rb b/app/controllers/admin/contacts_controller.rb index 685a08c86..793fa1209 100644 --- a/app/controllers/admin/contacts_controller.rb +++ b/app/controllers/admin/contacts_controller.rb @@ -30,7 +30,7 @@ module Admin if params[:only_no_country_code].eql?('1') contacts = contacts.where("ident_country_code is null or ident_country_code=''") end - contacts = contacts.email_not_verified if params[:email_not_verified].eql?('1') + contacts = contacts.email_verification_failed if params[:email_verification_failed].eql?('1') contacts end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8de3fdc70..5c742afce 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -108,4 +108,14 @@ module ApplicationHelper def body_css_class [controller_path.split('/').map!(&:dasherize), action_name.dasherize, 'page'].join('-') end + + def verified_email_span(verification) + content_tag(:span, verification.email, class: verified_email_class(verification)) + end + + def verified_email_class(verification) + return 'text-danger' if verification.failed? + return 'text-primary' if verification.not_verified? + return 'text-success' if verification.verified? + end end diff --git a/app/models/contact.rb b/app/models/contact.rb index a24a53a72..ac64b059f 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -23,10 +23,9 @@ class Contact < ApplicationRecord accepts_nested_attributes_for :legal_documents - scope :email_not_verified, lambda { - joins('LEFT JOIN :email_address_verifications emv ON contacts.email = emv.email') - .where('verified_at IS NULL OR verified_at <= ?', - EmailAddressVerification.verification_period) + 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 diff --git a/app/models/email_address_verification.rb b/app/models/email_address_verification.rb index 412ce7f83..b478ab0f8 100644 --- a/app/models/email_address_verification.rb +++ b/app/models/email_address_verification.rb @@ -6,7 +6,11 @@ class EmailAddressVerification < ApplicationRecord } scope :verified_recently, lambda { - where('verified_at IS NOT NULL and verified_at >= ?', verification_period) + 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) } def recently_verified? @@ -22,16 +26,28 @@ class EmailAddressVerification < ApplicationRecord 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 # media = success ? :mx : :smtp - media = :mx + media = :regex validation_request = Truemail.validate(email, with: media) if validation_request.result.success update(verified_at: Time.zone.now, success: true) else - update(verified_at: nil, + update(verified_at: Time.zone.now, success: false) end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 9abdfdb68..470d768b7 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -13,16 +13,6 @@ class Registrar < ApplicationRecord has_many :nameservers, through: :domains has_many :whois_records has_many :white_ips, dependent: :destroy - # belongs_to :email_address_verification, class_name: 'EmailAddressVerification', - # primary_key: 'email', - # foreign_key: 'email', - # optional: true, - # inverse_of: :registrar - # belongs_to :billing_email_address_verification, class_name: 'EmailAddressVerification', - # primary_key: 'email', - # foreign_key: 'billing_email', - # optional: true, - # inverse_of: :billing_registrar delegate :balance, to: :cash_account, allow_nil: true diff --git a/app/views/admin/contacts/index.haml b/app/views/admin/contacts/index.haml index bf3665664..cbd11d3fc 100644 --- a/app/views/admin/contacts/index.haml +++ b/app/views/admin/contacts/index.haml @@ -65,8 +65,8 @@ = check_box_tag :only_no_country_code, '1',params[:only_no_country_code].eql?('1'), style: 'width:auto;height:auto;float:right' .col-md-3 .form-group - = label_tag :email_not_verified, "Email not verified" - = check_box_tag :email_not_verified, '1',params[:email_not_verified].eql?('1'), style: 'width:auto;height:auto;float:right' + = label_tag :email_verification_failed, "Email verification failed" + = check_box_tag :email_verification_failed, '1',params[:email_verification_failed].eql?('1'), style: 'width:auto;height:auto;float:right' .row .col-md-3{style: 'padding-top: 25px;float:right;'} @@ -100,8 +100,7 @@ %td= link_to(contact, admin_contact_path(contact)) %td= contact.code %td= ident_for(contact) - %td{class: ('text-danger' unless contact.email_verification.success)} - = contact.email + %td= verified_email_span(contact.email_verification) %td= l(contact.created_at, format: :short) %td - if contact.registrar diff --git a/app/views/admin/contacts/partials/_general.haml b/app/views/admin/contacts/partials/_general.haml index c4a151294..6568cd3d0 100644 --- a/app/views/admin/contacts/partials/_general.haml +++ b/app/views/admin/contacts/partials/_general.haml @@ -17,8 +17,7 @@ %dd= ident_for(@contact) %dt= t(:email) - %dd{class: ('text-danger' unless @contact.email_verification&.success)} - = @contact.email + %dd= verified_email_span(@contact.email_verification) %dt= t(:phone) %dd= @contact.phone diff --git a/app/views/admin/registrars/index.html.erb b/app/views/admin/registrars/index.html.erb index 6ed864972..e641f5294 100644 --- a/app/views/admin/registrars/index.html.erb +++ b/app/views/admin/registrars/index.html.erb @@ -49,13 +49,9 @@ <%= "#{x.test_registrar}" %>