Class: EtFakeCcd::Validator::OtpValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/et_fake_ccd/validator/otp_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(secret: ::EtFakeCcd.config.microservice_secret, **args) ⇒ OtpValidator

Returns a new instance of OtpValidator.



5
6
7
8
# File 'lib/et_fake_ccd/validator/otp_validator.rb', line 5

def initialize(secret: ::EtFakeCcd.config.microservice_secret, **args)
  self.otp = ROTP::TOTP.new(secret)
  super
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



10
11
12
# File 'lib/et_fake_ccd/validator/otp_validator.rb', line 10

def validate_each(record, attribute, value)
  record.errors.add :one_time_password, 'Invalid oneTimePassword' unless otp.verify(value, drift_behind: 15)
end