Module: Authlogic::ORMAdapters::ActiveRecordAdapter::ActsAsAuthentic::SingleAccess

Defined in:
lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb

Overview

Single Access

Instead of repeating myself here, checkout the README. There is a “Tokens” section in there that goes over the single access token. Keep in mind none of this will be applied if there is not a single_access_token field supplied in the database.

Instance Methods

  • reset_{options[:single_access_token_field]} - resets the single access token with the friendly_unique_token

  • reset_{options[:single_access_token_field]}! - same as above, but saves the record afterwards

Alias Method Chains

  • {options[:password_field]} - if the :change_single_access_token_with_password is set to true, reset_:single_access_token_field will be called when the password changes

Instance Method Summary collapse

Instance Method Details

#acts_as_authentic_with_single_access(options = {}) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb', line 19

def acts_as_authentic_with_single_access(options = {})
  acts_as_authentic_without_single_access(options)
  
  return if options[:single_access_token_field].blank?
  
  class_eval <<-"end_eval", __FILE__, __LINE__
    validates_uniqueness_of :#{options[:single_access_token_field]}, :if => :#{options[:single_access_token_field]}_changed?
  
    before_validation :set_#{options[:single_access_token_field]}_field
  
    def password_with_single_access=(value)
      reset_#{options[:single_access_token_field]} if #{options[:change_single_access_token_with_password].inspect}
      self.password_without_single_access = value
    end
    alias_method_chain :password=, :single_access
  
    def reset_#{options[:single_access_token_field]}
      self.#{options[:single_access_token_field]} = self.class.friendly_unique_token
    end
  
    def reset_#{options[:single_access_token_field]}!
      reset_#{options[:single_access_token_field]}
      save_without_session_maintenance
    end
  
    protected
      def set_#{options[:single_access_token_field]}_field
        reset_#{options[:single_access_token_field]} if #{options[:single_access_token_field]}.blank?
      end
  end_eval
end