Class: Lockie::FailureApp
- Inherits:
-
ActionController::Metal
- Object
- ActionController::Metal
- Lockie::FailureApp
- Includes:
- ActionController::Redirecting
- Defined in:
- lib/lockie/failure_app.rb
Class Method Summary collapse
Instance Method Summary collapse
- #api_response(format = :text) ⇒ Object
- #html_response ⇒ Object
- #message ⇒ Object
- #type ⇒ Object
- #unauthenticated ⇒ Object
- #warden ⇒ Object
- #warden_options ⇒ Object
Class Method Details
.call(*args) ⇒ Object
8 9 10 11 |
# File 'lib/lockie/failure_app.rb', line 8 def self.call(*args) req = ActionDispatch::Request.new(*args) action(req.env['warden.options'][:action]).call(*args) end |
Instance Method Details
#api_response(format = :text) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/lockie/failure_app.rb', line 23 def api_response(format = :text) self.status = 401 self.content_type = request.format.to_s if format.eql?(:text) self.response_body = else self.response_body = { message: }.to_json end end |
#html_response ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lockie/failure_app.rb', line 33 def html_response flash[type] = if self.status = 302 if Lockie.config.callback_url uri = URI([:unauthenticated_path] || Lockie.config.unauthenticated_path) # only add callback_url if original path is not the same with login path unless request.original_fullpath == uri.path callback_url = request.base_url + request.original_fullpath uri.query = (uri.query.to_s.split("&") << "callback_url=#{ callback_url }").join("&") end redirect_to uri.to_s else redirect_to Lockie.config.unauthenticated_path end end |
#message ⇒ Object
49 50 51 |
# File 'lib/lockie/failure_app.rb', line 49 def @message ||= request.env['warden.message'] end |
#type ⇒ Object
57 58 59 |
# File 'lib/lockie/failure_app.rb', line 57 def type @type ||= [:type] || :error end |
#unauthenticated ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/lockie/failure_app.rb', line 13 def unauthenticated if request.xhr? api_response(:text) elsif request.format.to_sym == :json || request.content_type.to_s.split("/").last == 'json' api_response(:json) else html_response end end |
#warden ⇒ Object
61 62 63 |
# File 'lib/lockie/failure_app.rb', line 61 def warden request.env['warden'] end |
#warden_options ⇒ Object
53 54 55 |
# File 'lib/lockie/failure_app.rb', line 53 def request.env['warden.options'] end |