Class: TfaSession

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Attributes, ActiveModel::Model
Defined in:
lib/generators/authentication/templates/models/tfa_session.rb

Overview

Form object for handling two-factor authentication sessions

Automatically generated by the orthodox gem (https://github.com/bodacious/orthodox)

Constant Summary collapse

OTP_FORMAT =

Regex for OTP format

/\A\d{3,5}\Z|/
RECOVERY_CODE_FORMAT =

Regex for recovery code format

/\A\w{5}\-\w{5}\Z/

Instance Method Summary collapse

Instance Method Details

#otp?Boolean

===========================

= Public instance methods =

Returns:

  • (Boolean)


51
52
53
# File 'lib/generators/authentication/templates/models/tfa_session.rb', line 51

def otp?
  otp.present?
end

#otp_correctObject (private)

============================

= Private instance methods =



65
66
67
68
69
# File 'lib/generators/authentication/templates/models/tfa_session.rb', line 65

def otp_correct
  unless record.valid_otp?(otp.to_s)
    errors.add(:base, "OTP code was not correct")
  end
end

#recovery_code?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/generators/authentication/templates/models/tfa_session.rb', line 55

def recovery_code?
  recovery_code.present?
end

#recovery_code_correctObject (private)



71
72
73
74
75
# File 'lib/generators/authentication/templates/models/tfa_session.rb', line 71

def recovery_code_correct
  unless record.valid_recovery_code?(recovery_code.to_s)
    errors.add(:base, "Recovery code was not correct")
  end    
end