Module: MinimalistAuthentication::VerifiableToken

Extended by:
ActiveSupport::Concern
Defined in:
lib/minimalist_authentication/verifiable_token.rb

Constant Summary collapse

TOKEN_EXPIRATION_HOURS =
6

Instance Method Summary collapse

Instance Method Details

#matches_verification_token?(token) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/minimalist_authentication/verifiable_token.rb', line 23

def matches_verification_token?(token)
  token.present? && verification_token_valid? && secure_match?(token)
end

#regenerate_verification_tokenObject

generate secure verification_token and record generation time



10
11
12
# File 'lib/minimalist_authentication/verifiable_token.rb', line 10

def regenerate_verification_token
  update_token
end

#secure_update(token, attributes) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/minimalist_authentication/verifiable_token.rb', line 14

def secure_update(token, attributes)
  if matches_verification_token?(token)
    update(attributes) && clear_token
  else
    errors.add(:base, "Verification token check failed")
    false
  end
end

#verification_token_valid?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/minimalist_authentication/verifiable_token.rb', line 27

def verification_token_valid?
  return false if verification_token.blank? || verification_token_generated_at.blank?

  verification_token_generated_at > TOKEN_EXPIRATION_HOURS.hours.ago
end