Class: Devise::FailureApp
- Inherits:
-
Object
- Object
- Devise::FailureApp
- Includes:
- Warden::Mixins::Common
- 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.
Constant Summary collapse
- @@default_message =
:unauthenticated
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(env) ⇒ FailureApp
constructor
A new instance of FailureApp.
-
#query_string_for(options) ⇒ Object
Build the proper query string based on the given message.
- #respond! ⇒ Object
-
#store_location!(scope) ⇒ Object
Stores requested uri to redirect the user after signing in.
Constructor Details
#initialize(env) ⇒ FailureApp
Returns a new instance of FailureApp.
17 18 19 |
# File 'lib/devise/failure_app.rb', line 17 def initialize(env) @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/devise/failure_app.rb', line 7 def env @env end |
Class Method Details
.call(env) ⇒ Object
13 14 15 |
# File 'lib/devise/failure_app.rb', line 13 def self.call(env) new(env).respond! end |
Instance Method Details
#query_string_for(options) ⇒ Object
Build the proper query string based on the given message.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/devise/failure_app.rb', line 42 def query_string_for() = @env['warden'].try(:message) || [:message] || params = case when Symbol { => true } when String { :message => } else {} end Rack::Utils.build_query(params) end |
#respond! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/devise/failure_app.rb', line 21 def respond! = @env['warden.options'] scope = [:scope] redirect_path = if mapping = Devise.mappings[scope] "#{mapping.parsed_path}/#{mapping.path_names[:sign_in]}" else "/#{default_url}" end query_string = query_string_for() store_location!(scope) headers = {} headers["Location"] = redirect_path headers["Location"] << "?" << query_string unless query_string.empty? headers["Content-Type"] = 'text/plain' [302, headers, ["You are being redirected to #{redirect_path}"]] end |
#store_location!(scope) ⇒ Object
Stores requested uri to redirect the user after signing in. We cannot use scoped session provided by warden here, since the user is not authenticated yet, but we still need to store the uri based on scope, so different scopes would never use the same uri to redirect.
61 62 63 |
# File 'lib/devise/failure_app.rb', line 61 def store_location!(scope) session[:"#{scope}.return_to"] = request.request_uri if request && request.get? end |