Class: Authlogic::ControllerAdapters::AbstractAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/authlogic/controller_adapters/abstract_adapter.rb

Overview

Allows you to use Authlogic in any framework you want, not just rails. See the RailsAdapter for an example of how to adapt Authlogic to work with your framework.

Constant Summary collapse

"The cookie_domain method has not been " \
"implemented by the controller adapter"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ AbstractAdapter

Returns a new instance of AbstractAdapter.



14
15
16
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 14

def initialize(controller)
  self.controller = controller
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args, &block) ⇒ Object (private)



93
94
95
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 93

def method_missing(id, *args, &block)
  controller.send(id, *args, &block)
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



12
13
14
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 12

def controller
  @controller
end

Instance Method Details

#authenticate_with_http_basicObject



18
19
20
21
22
23
24
25
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 18

def authenticate_with_http_basic
  @auth = Rack::Auth::Basic::Request.new(controller.request.env)
  if @auth.provided? && @auth.basic?
    yield(*@auth.credentials)
  else
    false
  end
end

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 31

def cookie_domain
  raise NotImplementedError, E_COOKIE_DOMAIN_ADAPTER
end

#cookiesObject



27
28
29
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 27

def cookies
  controller.cookies
end

#last_request_update_allowed?Boolean

You can disable the updating of ‘last_request_at` on a per-controller basis.

# in your controller
def last_request_update_allowed?
  false
end

For example, what if you had a javascript function that polled the server updating how much time is left in their session before it times out. Obviously you would want to ignore this request, because then the user would never time out. So you can do something like this in your controller:

def last_request_update_allowed?
  action_name != "update_session_time_left"
end

See ‘authlogic/session/magic_columns.rb` to learn more about the `last_request_at` column itself.

Returns:

  • (Boolean)


79
80
81
82
83
84
85
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 79

def last_request_update_allowed?
  if controller.respond_to?(:last_request_update_allowed?, true)
    controller.send(:last_request_update_allowed?)
  else
    true
  end
end

#paramsObject



35
36
37
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 35

def params
  controller.params
end

#requestObject



39
40
41
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 39

def request
  controller.request
end

#request_content_typeObject



43
44
45
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 43

def request_content_type
  request.content_type
end

#respond_to_missing?(*args) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 87

def respond_to_missing?(*args)
  super(*args) || controller.respond_to?(*args)
end

#responds_to_single_access_allowed?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 51

def responds_to_single_access_allowed?
  controller.respond_to?(:single_access_allowed?, true)
end

#sessionObject



47
48
49
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 47

def session
  controller.session
end

#single_access_allowed?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/authlogic/controller_adapters/abstract_adapter.rb', line 55

def single_access_allowed?
  controller.send(:single_access_allowed?)
end