Class: Kingsman::FailureApp
- Inherits:
-
Jets::BareController
- Object
- Jets::BareController
- Kingsman::FailureApp
- Defined in:
- lib/kingsman/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
-
.call(env) ⇒ Object
delegate :flash, to: :request.
-
.default_url_options(*args) ⇒ Object
Try retrieving the URL options from the parent controller (usually ApplicationController).
Instance Method Summary collapse
Class Method Details
.call(env) ⇒ Object
delegate :flash, to: :request
21 22 23 24 |
# File 'lib/kingsman/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/kingsman/failure_app.rb', line 29 def self.(*args) # if defined?(Kingsman.parent_controller.constantize) # Kingsman.parent_controller.constantize.try(:default_url_options) || {} # else {} # end end |
Instance Method Details
#http_auth ⇒ Object
47 48 49 50 51 52 |
# File 'lib/kingsman/failure_app.rb', line 47 def http_auth self.status = 401 self.headers["WWW-Authenticate"] = %(Basic realm=#{Kingsman.http_authentication_realm.inspect}) if http_auth_header? 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/kingsman/failure_app.rb', line 54 def recall header_info = 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 header_info.each do | var, value| if request.respond_to?(:set_header) request.set_header(var, value) else request.env[var] = value end end flash.now[:alert] = (:invalid) if is_flashing_format? self.response = recall_app([:recall]).call(request.env).tap { |response| response[0] = Rack::Utils.status_code( response[0].in?(300..399) ? Kingsman.responder.redirect_status : Kingsman.responder.error_status ) } end |
#redirect ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/kingsman/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] = end end redirect_to redirect_url end |
#respond ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/kingsman/failure_app.rb', line 37 def respond if http_auth? http_auth elsif [:recall] recall else redirect end end |