Class: NoPassword::Link::Verification
- Inherits:
-
Object
- Object
- NoPassword::Link::Verification
- Includes:
- ActiveModel::Model, ActiveModel::Validations
- Defined in:
- lib/nopassword/link/verification.rb
Overview
Validates a token provided via a link against the challenge stored in session. Uses constant-time comparison to prevent timing attacks.
Instance Attribute Summary collapse
-
#challenge ⇒ Object
readonly
Returns the value of attribute challenge.
-
#provided_token ⇒ Object
readonly
Returns the value of attribute provided_token.
Instance Method Summary collapse
-
#different_browser? ⇒ Boolean
Alias for clarity - this is the most common reason for missing challenge.
- #expired? ⇒ Boolean
-
#initialize(challenge:, provided_token:) ⇒ Verification
constructor
A new instance of Verification.
-
#missing_challenge? ⇒ Boolean
Returns true if no challenge exists in session (e.g., different browser).
-
#persisted? ⇒ Boolean
For form routing - verification is always "persisted" (exists in session).
-
#to_param ⇒ Object
For form routing - use the provided token as the ID.
- #verify ⇒ Object
Constructor Details
#initialize(challenge:, provided_token:) ⇒ Verification
Returns a new instance of Verification.
15 16 17 18 |
# File 'lib/nopassword/link/verification.rb', line 15 def initialize(challenge:, provided_token:) @challenge = challenge @provided_token = provided_token end |
Instance Attribute Details
#challenge ⇒ Object (readonly)
Returns the value of attribute challenge.
9 10 11 |
# File 'lib/nopassword/link/verification.rb', line 9 def challenge @challenge end |
#provided_token ⇒ Object (readonly)
Returns the value of attribute provided_token.
9 10 11 |
# File 'lib/nopassword/link/verification.rb', line 9 def provided_token @provided_token end |
Instance Method Details
#different_browser? ⇒ Boolean
Alias for clarity - this is the most common reason for missing challenge
45 46 47 |
# File 'lib/nopassword/link/verification.rb', line 45 def different_browser? missing_challenge? end |
#expired? ⇒ Boolean
34 35 36 37 |
# File 'lib/nopassword/link/verification.rb', line 34 def expired? return true if challenge.created_at.nil? Time.current > challenge.expires_at end |
#missing_challenge? ⇒ Boolean
Returns true if no challenge exists in session (e.g., different browser)
40 41 42 |
# File 'lib/nopassword/link/verification.rb', line 40 def missing_challenge? challenge.token.blank? end |
#persisted? ⇒ Boolean
For form routing - verification is always "persisted" (exists in session)
25 26 27 |
# File 'lib/nopassword/link/verification.rb', line 25 def persisted? true end |
#to_param ⇒ Object
For form routing - use the provided token as the ID
30 31 32 |
# File 'lib/nopassword/link/verification.rb', line 30 def to_param provided_token end |
#verify ⇒ Object
20 21 22 |
# File 'lib/nopassword/link/verification.rb', line 20 def verify valid? end |