Sha256: 64cb3ac53e8c2fafe9475d2b9c30cc63f86a67cda17743874aeb51b9cd4f3fa9

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

module Authlogic
  module ControllerAdapters
    # = Merb Adapter
    # Adapts authlogic to work with merb. The point is to close the gap between what authlogic expects and what the merb controller object
    # provides. Similar to how ActiveRecord has an adapter for MySQL, PostgreSQL, SQLite, etc.
    class MerbAdapter < AbstractAdapter
      attr_accessor :controller
      
      def initialize(controller)
        self.controller = controller
      end
      
      def authenticate_with_http_basic(&block)
        @auth = Rack::Auth::Basic::Request.new(controller.request.env)
        if @auth.provided? and @auth.basic?
          black.call(*@auth.credentials)
        else
          false
        end
      end
      
      def cookies
        controller.cookies
      end
      
      def request
        controller.request
      end
      
      def session
        controller.session
      end
      
      # = Merb Implementation
      # Lets Authlogic know about the controller object, AKA "activates" authlogic.
      module MerbImplementation
        def self.included(klass) # :nodoc:
          klass.before :activate_authlogic
        end

        private
          def activate_authlogic
            Authlogic::Session::Base.controller = MerbAdapter.new(self)
          end
      end
    end
  end
end
 
# make sure we're running inside Merb
if defined?(Merb::Plugins)
  Merb::BootLoader.before_app_loads do
    Merb::Controller.send(:include, Authlogic::ControllerAdapters::MerbAdapter::MerbImplementation)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authlogic-1.0.0 lib/authlogic/controller_adapters/merb_adapter.rb