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)


21
22
23
# File 'lib/minimalist_authentication/verifiable_token.rb', line 21

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



8
9
10
# File 'lib/minimalist_authentication/verifiable_token.rb', line 8

def regenerate_verification_token
  update_token
end

#secure_update(token, attributes) ⇒ Object



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

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

#verification_token_valid?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/minimalist_authentication/verifiable_token.rb', line 25

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