Module: Authlogic::ActsAsAuthentic::PerishableToken::Methods::ClassMethods

Defined in:
lib/authlogic/acts_as_authentic/perishable_token.rb

Overview

Class level methods for the perishable token

Instance Method Summary (collapse)

Instance Method Details

- (Object) find_using_perishable_token(token, age = self.perishable_token_valid_for)

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)


63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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

- (Object) find_using_perishable_token!(token, age = perishable_token_valid_for)

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



79
80
81
# 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