Sha256: 524fbde07c16c5709c774f44b1e0a53c3e97403674284e4355b2b5f3d7c2325f

Contents?: true

Size: 879 Bytes

Versions: 2

Compression:

Stored size: 879 Bytes

Contents

# frozen_string_literal: true

module SwitchUser
  module Provider
    class Sorcery < Base
      def initialize(controller)
        @controller = controller
      end

      def login(user, _scope = nil)
        @controller.auto_login(user)
      end

      def logout(_scope = nil)
        save_original_user_identifier if SwitchUser.switch_back

        @controller.logout

        restore_original_user_identifier
      end

      def save_original_user_identifier
        @original_user_scope_identifier = @controller.session[:original_user_scope_identifier]
      end

      def restore_original_user_identifier
        if @original_user_scope_identifier
          @controller.session[:original_user_scope_identifier] = @original_user_scope_identifier
        end
      end

      def current_user(_scope = nil)
        @controller.current_user
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
switch_user-1.5.2 lib/switch_user/provider/sorcery.rb
switch_user-1.5.1 lib/switch_user/provider/sorcery.rb