Add verification methods

This commit is contained in:
Alex Sherman 2020-06-05 17:21:43 +05:00
parent cc142076c3
commit 9ae85f3d74
2 changed files with 12 additions and 2 deletions

View file

@ -3,12 +3,12 @@ module Concerns
extend ActiveSupport::Concern extend ActiveSupport::Concern
def email_verification def email_verification
EmailAddressVerification.find_by(email: self.email) EmailAddressVerification.find_or_create_by(email: self.email)
end end
def billing_email_verification def billing_email_verification
if self.attribute_names.include?('billing_email') if self.attribute_names.include?('billing_email')
EmailAddressVerification.find_by(email: self.billing_email) EmailAddressVerification.find_or_create_by(email: self.billing_email)
else else
nil nil
end end

View file

@ -1,4 +1,14 @@
class EmailAddressVerification < ApplicationRecord class EmailAddressVerification < ApplicationRecord
RECENTLY_VERIFIED_PERIOD = 1.month
def recently_verified?
verified_at > Time.zone.now - RECENTLY_VERIFIED_PERIOD
end
def verify
validation_request = Truemail.validate(email)
update(verified_at: Time.zone.now) if validation_request.result.success
end
end end