Sha256: e134dd1b3db458383dd96f779957888831fa79e267b5fb8f11b19401e82f5d28

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

# encoding: utf-8
require 'warden'
require 'active_support'

$:.unshift File.expand_path(File.dirname(__FILE__))
require "rails_warden/manager"
require "rails_warden/rails_settings"
require "rails_warden/controller_mixin"

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']
      @request = env['action_controller.rescue.request']
    else
      Rack::Request.new(env)
    end
  end

  def raw_session
    request.session
  end

  def reset_session!
    raw_session.inspect # why do I have to inspect it to get it to clear?
    raw_session.clear
  end
end

Warden::Manager.before_failure do |env, opts|
  env['warden'].request.params['action'] = RailsWarden.unauthenticated_action || "unauthenticated"
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
end


if defined?(Rails)
  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
end

class Warden::SessionSerializer
  def serialize(user)
    [user.class, user.id]
  end

  def deserialize(key)
    klass, id = key
    klass = case klass
            when Class
              klass
            when String, Symbol
              klass.to_s.classify.constantize
            end
    klass.find(id)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_warden-0.3.0 lib/rails_warden.rb