Sha256: 6fed449338e85e033fb07b145c7af5d386388bb77896b7b7040d325d746b04b7
Contents?: true
Size: 1.13 KB
Versions: 5
Compression:
Stored size: 1.13 KB
Contents
module Devise module FailureApp mattr_accessor :default_url # 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. def self.call(env) options = env['warden.options'] scope = options[:scope] message = env['warden'].try(:message) || options[:message] params = case message when Symbol { message => true } when String { :message => message } else {} end redirect_path = if mapping = Devise.mappings[scope] "#{mapping.parsed_path}/#{mapping.path_names[:sign_in]}" else "/#{default_url}" end query_string = Rack::Utils.build_query(params) 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 end end
Version data entries
5 entries across 5 versions & 1 rubygems