Class: LoyalPassport::Controllers::CustomFailureApp

Inherits:
Devise::FailureApp
  • Object
show all
Defined in:
lib/loyal_passport/controllers/custom_failure_app.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(env) ⇒ Object



22
23
24
25
# File 'lib/loyal_passport/controllers/custom_failure_app.rb', line 22

def self.call(env)
  @respond ||= action(:respond)
  @respond.(env)
end

Instance Method Details

#http_authObject



15
16
17
18
19
20
# File 'lib/loyal_passport/controllers/custom_failure_app.rb', line 15

def http_auth
  self.status = 401
  self.headers["WWW-Authenticate"] = %(Basic realm=#{Devise.http_authentication_realm.inspect}) if http_auth_header?
  self.content_type = request.format.to_s
  self.response_body = http_auth_body
end

#recallObject



27
28
29
30
31
# File 'lib/loyal_passport/controllers/custom_failure_app.rb', line 27

def recall
  env["PATH_INFO"]  = attempted_url
  flash.now[:alert] = i18n_message(:invalid)
  self.response = recall_app(warden_options[:recall]).call(env)
end

#redirectObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/loyal_passport/controllers/custom_failure_app.rb', line 33

def redirect
  # store_location!
  options = {}

  _redirect_url = redirect_url

  if (return_to = failures_url_return_to) && (return_to != _redirect_url)
    options[:return_to] = return_to
  end

  if flash[:timedout] && flash[:alert]
    flash.keep(:timedout)
    flash.keep(:alert)
  else
    flash[:alert] = i18n_message
  end

  if options.any?
    redirect_to "#{_redirect_url}?#{options.to_query}"
  else
    redirect_to _redirect_url
  end
end

#respondObject



5
6
7
8
9
10
11
12
13
# File 'lib/loyal_passport/controllers/custom_failure_app.rb', line 5

def respond
  if http_auth?
    http_auth
  elsif warden_options[:recall]
    recall
  else
    redirect
  end
end