18F/identity-idp

View on GitHub
app/models/gpo_confirmation_code.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

class GpoConfirmationCode < ApplicationRecord
  self.table_name = 'usps_confirmation_codes'

  belongs_to :profile

  def self.first_with_otp(otp)
    find do |gpo_confirmation_code|
      Pii::Fingerprinter.verify(
        Base32::Crockford.normalize(otp),
        gpo_confirmation_code.otp_fingerprint,
      )
    end
  end

  def expired?
    code_sent_at < IdentityConfig.store.usps_confirmation_max_days.days.ago
  end
end