Class: RailsWarden::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_warden/manager.rb

Class Method Summary collapse

Class Method Details

.new(app, opts = {}, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rails_warden/manager.rb', line 5

def self.new(app, opts = {}, &block)
  # Get the failure application
  opts[:failure_app] = opts[:failure_app].to_s.classify.constantize if opts[:failure_app]
  opts[:default_strategies] = [opts[:defaults]].flatten if opts[:defaults]
  
  # Set the default user
  if user = opts.delete(:default_user)
    RailsWarden.default_user_class = user.to_s.classify.constantize
  end
  
  # Set the unauthenticated action if it's set
  if ua = opts.delete(:unauthenticated_action)
    RailsWarden.unauthenticated_action = ua
  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
  
  Warden::Manager.new(app, opts, &block)
end