Module: ActiveModel::OneTimePassword::InstanceMethodsOnActivation

Defined in:
lib/active_model/one_time_password.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_otp(code, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/active_model/one_time_password.rb', line 24

def authenticate_otp(code, options = {})
  totp = ROTP::TOTP.new(self.otp_column)
  if drift = options[:drift]
    totp.verify_with_drift(code, drift)
  else
    totp.verify(code)
  end
end

#otp_code(time = Time.now) ⇒ Object



33
34
35
# File 'lib/active_model/one_time_password.rb', line 33

def otp_code(time = Time.now)
  ROTP::TOTP.new(self.otp_column).at(time)
end

#otp_columnObject



42
43
44
# File 'lib/active_model/one_time_password.rb', line 42

def otp_column
  self.send(self.class.otp_column_name)
end

#otp_column=(attr) ⇒ Object



46
47
48
# File 'lib/active_model/one_time_password.rb', line 46

def otp_column=(attr)
  self.send("#{self.class.otp_column_name}=", attr)
end

#provisioning_uri(account = nil) ⇒ Object



37
38
39
40
# File 'lib/active_model/one_time_password.rb', line 37

def provisioning_uri( = nil)
   ||= self.email if self.respond_to?(:email)
  ROTP::TOTP.new(self.otp_column).provisioning_uri()
end