Class: Devise::FailureApp
- Inherits:
-
ActionController::Metal
- Object
- ActionController::Metal
- Devise::FailureApp
show all
- Includes:
- 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. It is responsible for redirecting the user to the sign in page based on current scope and mapping. If no scope is given, it redirects to the default_url.
Class Method Summary
collapse
Instance Method Summary
collapse
#store_location_for, #stored_location_for
Class Method Details
.call(env) ⇒ Object
21
22
23
24
|
# File 'lib/devise/failure_app.rb', line 21
def self.call(env)
@respond ||= action(:respond)
@respond.call(env)
end
|
.default_url_options(*args) ⇒ Object
Try retrieving the URL options from the parent controller (usually ApplicationController). Instance methods are not supported at the moment, so only the class-level attribute is used.
29
30
31
32
33
34
35
|
# File 'lib/devise/failure_app.rb', line 29
def self.default_url_options(*args)
if defined?(Devise.parent_controller.constantize)
Devise.parent_controller.constantize.try(:default_url_options) || {}
else
{}
end
end
|
Instance Method Details
#http_auth ⇒ Object
47
48
49
50
51
52
|
# File 'lib/devise/failure_app.rb', line 47
def http_auth
self.status = 401
self.["WWW-Authenticate"] = %(Basic realm=#{Devise.http_authentication_realm.inspect}) if
self.content_type = request.format.to_s
self.response_body = http_auth_body
end
|
#recall ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/devise/failure_app.rb', line 54
def recall
= if relative_url_root?
base_path = Pathname.new(relative_url_root)
full_path = Pathname.new(attempted_path)
{ "SCRIPT_NAME" => relative_url_root,
"PATH_INFO" => '/' + full_path.relative_path_from(base_path).to_s }
else
{ "PATH_INFO" => attempted_path }
end
.each do | var, value|
if request.respond_to?(:set_header)
request.(var, value)
else
request.env[var] = value
end
end
flash.now[:alert] = i18n_message(:invalid) if is_flashing_format?
self.response = recall_app(warden_options[:recall]).call(request.env).tap { |response|
response[0] = Rack::Utils.status_code(
response[0].in?(300..399) ? Devise.responder.redirect_status : Devise.responder.error_status
)
}
end
|
#redirect ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/devise/failure_app.rb', line 81
def redirect
store_location!
if is_flashing_format?
if flash[:timedout] && flash[:alert]
flash.keep(:timedout)
flash.keep(:alert)
else
flash[:alert] = i18n_message
end
end
redirect_to redirect_url
end
|
#respond ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/devise/failure_app.rb', line 37
def respond
if http_auth?
http_auth
elsif warden_options[:recall]
recall
else
redirect
end
end
|