Class: SwitchUser::Provider::Sorcery

Inherits:
Base
  • Object
show all
Defined in:
lib/switch_user/provider/sorcery.rb

Instance Method Summary collapse

Methods inherited from Base

#clear_original_user, #current_user?, #current_users_without_scope, #login_exclusive, #login_inclusive, #logout_all, #original_user, #original_user=, #remember_current_user

Constructor Details

#initialize(controller) ⇒ Sorcery

Returns a new instance of Sorcery.



6
7
8
# File 'lib/switch_user/provider/sorcery.rb', line 6

def initialize(controller)
  @controller = controller
end

Instance Method Details

#current_user(_scope = nil) ⇒ Object



31
32
33
# File 'lib/switch_user/provider/sorcery.rb', line 31

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

#login(user, _scope = nil) ⇒ Object



10
11
12
# File 'lib/switch_user/provider/sorcery.rb', line 10

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

#logout(_scope = nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/switch_user/provider/sorcery.rb', line 14

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

  @controller.logout

  restore_original_user_identifier
end

#restore_original_user_identifierObject



26
27
28
29
# File 'lib/switch_user/provider/sorcery.rb', line 26

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

#save_original_user_identifierObject



22
23
24
# File 'lib/switch_user/provider/sorcery.rb', line 22

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