Sha256: 5c245c03e474306908e4b3c78ffd21d06226881889c62e9562dd4c7c04c86918

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

here = File.dirname(__FILE__)

require 'rubygems'
require 'warden'
require 'active_support'
require "#{here}/rails_warden/manager"
require "#{here}/rails_warden/rails_settings"
require "#{here}/rails_warden/controller_mixin"

Warden::Manager.before_failure do |env, opts|
  request = env["action_controller.rescue.request"]
  request.params["action"] = RailsWarden.unauthenticated_action || "unauthenticated"
end

if defined?(Rails)
  Rails.configuration.after_initialize do
    ActionController::Base.class_eval{ include RailsWarden::ControllerMixin }
  end
end

# Session Serialization in.  This block determines how the user will 
# be stored in the session.  If you're using a complex object like an 
# ActiveRecord model, it is not a good idea to store the complete object.
# An ID is sufficient
Warden::Manager.serialize_into_session{ |user| [user.class, user.id] } 

# Session Serialization out.  This block gets the user out of the session.
# It should be the reverse of serializing the object into the session
Warden::Manager.serialize_from_session do |klass, id| 
  klass = case klass
  when Class
    klass
  when String, Symbol
    klass.to_s.classify.constantize
  end
  klass.find(id)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_warden-0.1.1 lib/rails_warden.rb