Class: Devise::FailureApp

Inherits:
ActionController::Metal
  • Object
show all
Includes:
ActionController::RackDelegation, ActionController::Redirecting, ActionController::UrlFor, Controllers::StoreLocation
Defined in:
lib/devise/failure_app.rb

Overview

Failure application that will be called every time :warden is thrown from any strategy or hook. Responsible for redirect the user to the sign in page based on current scope and mapping. If no scope is given, redirect to the default_url.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Controllers::StoreLocation

#store_location_for, #stored_location_for

Class Method Details

.call(env) ⇒ Object



20
21
22
23
# File 'lib/devise/failure_app.rb', line 20

def self.call(env)
  @respond ||= action(:respond)
  @respond.call(env)
end

.default_url_options(*args) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/devise/failure_app.rb', line 25

def self.default_url_options(*args)
  if defined?(ApplicationController)
    ApplicationController.default_url_options(*args)
  else
    {}
  end
end

Instance Method Details

#http_authObject



43
44
45
46
47
48
# File 'lib/devise/failure_app.rb', line 43

def http_auth
  self.status = 401
  self.headers["WWW-Authenticate"] = %(Basic realm=#{Devise.http_authentication_realm.inspect}) if http_auth_header?
  self.content_type = request.format.to_s
  self.response_body = http_auth_body
end

#recallObject



50
51
52
53
54
# File 'lib/devise/failure_app.rb', line 50

def recall
  env["PATH_INFO"]  = attempted_path
  flash.now[:alert] = i18n_message(:invalid)
  self.response = recall_app(warden_options[:recall]).call(env)
end

#redirectObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/devise/failure_app.rb', line 56

def redirect
  store_location!
  if flash[:timedout] && flash[:alert]
    flash.keep(:timedout)
    flash.keep(:alert)
  else
    flash[:alert] = i18n_message
  end
  redirect_to redirect_url
end

#respondObject



33
34
35
36
37
38
39
40
41
# File 'lib/devise/failure_app.rb', line 33

def respond
  if http_auth?
    http_auth
  elsif warden_options[:recall]
    recall
  else
    redirect
  end
end