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.
-
#redirect_path_for(scope) ⇒ Object
Build the path based on current scope.
- #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.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/devise/failure_app.rb', line 38 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 |
#redirect_path_for(scope) ⇒ Object
Build the path based on current scope.
54 55 56 57 58 59 60 |
# File 'lib/devise/failure_app.rb', line 54 def redirect_path_for(scope) if mapping = Devise.mappings[scope] "#{mapping.parsed_path}/#{mapping.path_names[:sign_in]}" else "/#{default_url}" end end |
#respond! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/devise/failure_app.rb', line 21 def respond! = @env['warden.options'] scope = [:scope] redirect_path = redirect_path_for(scope) 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.
66 67 68 69 70 |
# File 'lib/devise/failure_app.rb', line 66 def store_location!(scope) if request && request.get? && !request.xhr? session[:"#{scope}.return_to"] = request.request_uri end end |