Class: Bsm::Sso::Client::FailureApp

Inherits:
ActionController::Metal
  • Object
show all
Includes:
ActionController::Redirecting, UrlHelpers
Defined in:
lib/bsm/sso/client/failure_app.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UrlHelpers

#service_url

Class Method Details

.call(env) ⇒ Object



5
6
7
# File 'lib/bsm/sso/client/failure_app.rb', line 5

def self.call(env)
  action(:respond).call(env)
end

.default_url_options(*args) ⇒ Object



9
10
11
# File 'lib/bsm/sso/client/failure_app.rb', line 9

def self.default_url_options(*args)
  ApplicationController.default_url_options(*args)
end

Instance Method Details

#redirect!Object



21
22
23
24
# File 'lib/bsm/sso/client/failure_app.rb', line 21

def redirect!
  path = request.env['warden.options'].try(:[], :attempted_path) || request.fullpath
  redirect_to Bsm::Sso::Client.user_class.(service: service_url(path)), status: 303
end

#respondObject



13
14
15
16
17
18
19
# File 'lib/bsm/sso/client/failure_app.rb', line 13

def respond
  if Bsm::Sso::Client.navigational_formats.include?(request.format.try(:to_sym)) || request.accepts.include?(Mime[:html])
    request.xhr? ? respond_with_js! : redirect!
  else
    stop!
  end
end

#respond_with_js!Object



26
27
28
29
30
# File 'lib/bsm/sso/client/failure_app.rb', line 26

def respond_with_js!
  self.status = :ok
  self.content_type  = request.format.to_s
  self.response_body = "alert('Your session has expired');"
end

#stop!Object



32
33
34
35
36
# File 'lib/bsm/sso/client/failure_app.rb', line 32

def stop!
  self.status = 403
  self.content_type  = Mime[:html]
  self.response_body = '<html><head></head><body><h1>Access Forbidden</h1></body></html>'
end