Class: Devise::FailureApp
- Inherits:
-
ActionController::Metal
- Object
- ActionController::Metal
- Devise::FailureApp
show all
- Includes:
- AbstractController::Callbacks, 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
[View source]
26
27
28
29
|
# File 'lib/devise/failure_app.rb', line 26
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.
[View source]
34
35
36
37
38
39
40
|
# File 'lib/devise/failure_app.rb', line 34
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
[View source]
52
53
54
55
56
57
|
# File 'lib/devise/failure_app.rb', line 52
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
[View source]
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/devise/failure_app.rb', line 59
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
[View source]
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/devise/failure_app.rb', line 86
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
[View source]
42
43
44
45
46
47
48
49
50
|
# File 'lib/devise/failure_app.rb', line 42
def respond
if http_auth?
http_auth
elsif warden_options[:recall]
recall
else
redirect
end
end
|