How does the ranger get the current user from the rack?

After the user has logged in ( ENV['warden'].authenticate!'d) once, how wardendoes this know? I cannot find anything in the cookie except the value rack.session- I could not figure it out from the documentation or code.

+4
source share
1 answer

In development /lib/devise/controllerlers/helpers.rb: 35

def devise_group(group_name, opts={})
      mappings = "[#{ opts[:contains].map { |m| ":#{m}" }.join(',') }]"

      class_eval <<-METHODS, __FILE__, __LINE__ + 1
        def authenticate_#{group_name}!(favourite=nil, opts={})
          unless #{group_name}_signed_in?
            mappings = #{mappings}
            mappings.unshift mappings.delete(favourite.to_sym) if favourite
            mappings.each do |mapping|
              opts[:scope] = mapping
              warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
            end
          end
        end
        def #{group_name}_signed_in?
          #{mappings}.any? do |mapping|
            warden.authenticate?(scope: mapping)
          end
        end
        def current_#{group_name}(favourite=nil)
          mappings = #{mappings}
          mappings.unshift mappings.delete(favourite.to_sym) if favourite
          mappings.each do |mapping|
            current = warden.authenticate(scope: mapping)
            return current if current
          end
          nil
        end
        def current_#{group_name.to_s.pluralize}
          #{mappings}.map do |mapping|
            warden.authenticate(scope: mapping)
          end.compact
        end
        helper_method "current_#{group_name}", "current_#{group_name.to_s.pluralize}", "#{group_name}_signed_in?"
      METHODS
    end

https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.rb

: devise_group , (, current_user), , warden.authenticate,

  def warden
    request.env['warden']
  end

0

Source: https://habr.com/ru/post/1605971/


All Articles