module Authlogic::ActsAsAuthentic::PerishableToken::Methods::ClassMethods

Class level methods for the perishable token

Public Instance Methods

find_using_perishable_token(token, age = self.perishable_token_valid_for) click to toggle source

Use this method to find a record with a perishable token. This method does 2 things for you:

  1. It ignores blank tokens

  2. It enforces the perishable_token_valid_for configuration option.

If you want to use a different timeout value, just pass it as the second parameter:

User.find_using_perishable_token(token, 1.hour)
# File lib/authlogic/acts_as_authentic/perishable_token.rb, line 63
def find_using_perishable_token(token, age = self.perishable_token_valid_for)
  return if token.blank?
  age = age.to_i

  conditions_sql = "perishable_token = ?"
  conditions_subs = [token]

  if column_names.include?("updated_at") && age > 0
    conditions_sql += " and updated_at > ?"
    conditions_subs << age.seconds.ago
  end

  where(conditions_sql, *conditions_subs).first
end
find_using_perishable_token!(token, age = perishable_token_valid_for) click to toggle source

This method will raise ActiveRecord::NotFound if no record is found.

# File lib/authlogic/acts_as_authentic/perishable_token.rb, line 79
def find_using_perishable_token!(token, age = perishable_token_valid_for)
  find_using_perishable_token(token, age) || raise(ActiveRecord::RecordNotFound)
end