Class: TfaSession
- Inherits:
-
Object
- Object
- TfaSession
- 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
-
#otp? ⇒ Boolean
=========================== = Public instance methods = ===========================.
-
#otp_correct ⇒ Object
private
============================ = Private instance methods = ============================.
- #recovery_code? ⇒ Boolean
- #recovery_code_correct ⇒ Object private
Instance Method Details
#otp? ⇒ Boolean
===========================
= Public instance methods =
51 52 53 |
# File 'lib/generators/authentication/templates/models/tfa_session.rb', line 51 def otp? otp.present? end |
#otp_correct ⇒ Object (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
55 56 57 |
# File 'lib/generators/authentication/templates/models/tfa_session.rb', line 55 def recovery_code? recovery_code.present? end |
#recovery_code_correct ⇒ Object (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 |