Module: Devise::Models::TwoFactorAuthenticatable::InstanceMethodsOnActivation

Defined in:
lib/two_factor_authentication/models/two_factor_authenticatable.rb

Instance Method Summary collapse

Instance Method Details

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



29
30
31
32
33
34
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 29

def authenticate_otp(code, options = {})
  totp = ROTP::TOTP.new(self.otp_column, { digits: options[:otp_length] || self.class.otp_length })
  drift = options[:drift] || self.class.allowed_otp_drift_seconds

  totp.verify_with_drift(code, drift)
end

#max_login_attemptsObject



65
66
67
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 65

def 
  self.class.
end

#max_login_attempts?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 61

def 
  second_factor_attempts_count.to_i >= .to_i
end

#need_two_factor_authentication?(request) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 53

def need_two_factor_authentication?(request)
  true
end

#otp_code(time = Time.now, options = {}) ⇒ Object



36
37
38
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 36

def otp_code(time = Time.now, options = {})
  ROTP::TOTP.new(self.otp_column, { digits: options[:otp_length] || self.class.otp_length }).at(time, true)
end

#otp_columnObject



45
46
47
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 45

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

#otp_column=(attr) ⇒ Object



49
50
51
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 49

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

#populate_otp_columnObject



69
70
71
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 69

def populate_otp_column
  self.otp_column = ROTP::Base32.random_base32
end

#provisioning_uri(account = nil, options = {}) ⇒ Object



40
41
42
43
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 40

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

#send_two_factor_authentication_codeObject

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 57

def send_two_factor_authentication_code
  raise NotImplementedError.new("No default implementation - please define in your class.")
end