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

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#find_using_perishable_token(token, age = perishable_token_valid_for) ⇒ Object

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)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/authlogic/acts_as_authentic/perishable_token.rb', line 79

def find_using_perishable_token(token, age = perishable_token_valid_for)
  return if token.blank?
  age = age.to_i

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

  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) ⇒ Object

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



95
96
97
# File 'lib/authlogic/acts_as_authentic/perishable_token.rb', line 95

def find_using_perishable_token!(token, age = perishable_token_valid_for)
  find_using_perishable_token(token, age) || raise(ActiveRecord::RecordNotFound)
end