Add thirs status - verification failed

This commit is contained in:
Alex Sherman 2020-06-12 15:37:53 +05:00
parent f8eea08357
commit 56ac816dd1
13 changed files with 96 additions and 40 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -49,13 +49,9 @@
<%= "#{x.test_registrar}" %>
</td>
<td>
<span class=<%= 'text-danger' unless x.email_verification&.success %>>
<%= "#{x.email}" %>
</span>
<%= verified_email_span(x.email_verification) %>
<% if x[:billing_email].present? %>
<span class=<%= 'text-danger' unless x.billing_email_verification&.success %>>
<%= "#{x[:billing_email]}" %>
</span>
<%= verified_email_span(x.billing_email_verification) %>
<% end %>
</td>
</tr>

View file

@ -15,8 +15,8 @@
<dd><%= registrar.accounting_customer_code %></dd>
<dt><%= Registrar.human_attribute_name :billing_email %></dt>
<dd class=<%= 'text-danger' unless @registrar.billing_email_verification&.success%>>
<%= registrar.billing_email %>
<dd>
<%= verified_email_span(registrar.billing_email_verification) %>
</dd>
<dt><%= Registrar.human_attribute_name :reference_no %></dt>

View file

@ -15,8 +15,8 @@
<dd><%= @registrar.phone %></dd>
<dt><%= Registrar.human_attribute_name :email %></dt>
<dd class=<%= 'text-danger' unless @registrar.email_verification&.success %>>
<%= @registrar.email %>
<dd>
<%= verified_email_span(@registrar.email_verification) %>
</dd>
</dl>
</div>