Class: SwitchUser::Provider::Base
- Inherits:
-
Object
- Object
- SwitchUser::Provider::Base
show all
- Defined in:
- lib/switch_user/provider/base.rb
Instance Method Summary
collapse
Instance Method Details
#clear_original_user ⇒ Object
55
56
57
|
# File 'lib/switch_user/provider/base.rb', line 55
def clear_original_user
@controller.session.delete(:original_user_scope_identifier)
end
|
#current_user?(user, scope = :user) ⇒ Boolean
59
60
61
|
# File 'lib/switch_user/provider/base.rb', line 59
def current_user?(user, scope = :user)
current_user(scope) == user
end
|
#current_users_without_scope ⇒ Object
4
5
6
7
8
9
10
|
# File 'lib/switch_user/provider/base.rb', line 4
def current_users_without_scope
SwitchUser.available_scopes.inject([]) do |users, scope|
user = current_user(scope)
users << user if user
users
end
end
|
#login_exclusive(user, args) ⇒ Object
12
13
14
15
16
17
|
# File 'lib/switch_user/provider/base.rb', line 12
def login_exclusive(user, args)
requested_scope = args.fetch(:scope, :user).to_sym
logout_all
login(user, requested_scope)
end
|
#login_inclusive(user, args) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/switch_user/provider/base.rb', line 19
def login_inclusive(user, args)
requested_scope = args.fetch(:scope, :user).to_sym
logout(requested_scope)
login(user, requested_scope)
end
|
#logout_all ⇒ Object
26
27
28
29
30
|
# File 'lib/switch_user/provider/base.rb', line 26
def logout_all
SwitchUser.available_scopes.each do |scope|
logout(scope)
end
end
|
#original_user ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/switch_user/provider/base.rb', line 32
def original_user
user_identifier = @controller.session[:original_user_scope_identifier]
if user_identifier
UserLoader.prepare(scope_identifier: user_identifier).user
end
end
|
#original_user=(user) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/switch_user/provider/base.rb', line 40
def original_user=(user)
user_type = user.class.to_s.underscore
user_identifier = "#{user_type}_#{user.id}"
@controller.session[:original_user_scope_identifier] = user_identifier
end
|
#remember_current_user(remember) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/switch_user/provider/base.rb', line 47
def remember_current_user(remember)
if remember
self.original_user = current_user
else
clear_original_user
end
end
|