lib/rails_warden.rb in rails_warden-0.3.0 vs lib/rails_warden.rb in rails_warden-0.5.0

- old
+ new

@@ -9,17 +9,51 @@ module Warden::Mixins::Common # Gets the rails request object by default if it's available def request return @request if @request - if env['action_controller.rescue.request'] + if defined?(ActionDispatch::Request) + @request = ActionDispatch::Request.new(env) + elsif env['action_controller.rescue.request'] @request = env['action_controller.rescue.request'] else Rack::Request.new(env) end end + def response + return @response if @response + if env['action_controller.rescue.response'] + @response = env['action_controller.rescue.response'] + else + Rack::Response.new(env) + end + end + + def cookies + unless defined?('ActionController::Cookies') + puts 'cookies was not defined' + return + end + @cookies ||= begin + # Duck typing... + controller = Struct.new(:request, :response) do + def self.helper_method(*args); end + end + controller.send(:include, ActionController::Cookies) + controller.new(self.request, self.response).send(:cookies) + end + end + + def logger + unless defined?('Rails') + puts 'logger not defined' + return + end + Rails.logger + end + def raw_session request.session end def reset_session! @@ -27,29 +61,45 @@ raw_session.clear end end Warden::Manager.before_failure do |env, opts| - env['warden'].request.params['action'] = RailsWarden.unauthenticated_action || "unauthenticated" + action = RailsWarden.unauthenticated_action || "unauthenticated" + if Rails.respond_to?(:version) && Rails.version >= "3" + env['action_dispatch.request.path_parameters'][:action] = action + else + env['warden'].request.params['action'] = action + end end # Rails needs the action to be passed in with the params Warden::Manager.before_failure do |env, opts| - if request = env["action_controller.rescue.request"] - request.params["action"] = RailsWarden.unauthenticated_action - end + env['warden'].request.params["action"] = RailsWarden.unauthenticated_action end -if defined?(Rails) +if !defined?(Rails::Railtie) Rails.configuration.after_initialize do class ActionController::Base include RailsWarden::Mixins::HelperMethods include RailsWarden::Mixins::ControllerOnlyMethods end module ApplicationHelper include RailsWarden::Mixins::HelperMethods + end + end +else + class RailsWarden::Railtie < Rails::Railtie + initializer :warden do + ActionController::Base.class_eval do + include RailsWarden::Mixins::HelperMethods + include RailsWarden::Mixins::ControllerOnlyMethods + end + + module ApplicationHelper + include RailsWarden::Mixins::HelperMethods + end end end end class Warden::SessionSerializer