switch_user 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +4 -4
- data/app/controllers/switch_user_controller.rb +19 -0
- data/lib/switch_user/version.rb +1 -1
- metadata +4 -5
- data/Gemfile.lock +0 -15
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
switch_user
|
2
2
|
===========
|
3
3
|
|
4
|
-
Inspired from [hobo][0], switch_user provides a convenient way to switch current user that speeds up your development.
|
4
|
+
Inspired from [hobo][0], switch_user provides a convenient way to switch current user that speeds up your development and reproduce user specified error on production.
|
5
5
|
|
6
6
|
Use Case
|
7
7
|
--------
|
@@ -10,7 +10,7 @@ switch_user is very useful in such use cases
|
|
10
10
|
|
11
11
|
1. switch current users in development so that you don't waste your time to logout, login and input email (login) or password any more.
|
12
12
|
|
13
|
-
2. reproduce the user specified error
|
13
|
+
2. reproduce the user specified error on production. Sometimes the error is only raised for specified user, which is difficult to reproduce for developers, switch_user can help you reproduce it by login as that user.
|
14
14
|
|
15
15
|
Example
|
16
16
|
-------
|
@@ -37,7 +37,7 @@ or haml
|
|
37
37
|
|
38
38
|
= switch_user_select
|
39
39
|
|
40
|
-
If there are too many users (
|
40
|
+
If there are too many users (on production), the switch_user_select is not a good choice, you should call the switch user request by yourself.
|
41
41
|
|
42
42
|
<%= link_to user.login, "/switch_user?scope_identifier=user_#{user.id}" %>
|
43
43
|
<%= link_to admin.login, "/switch_user?scope_identifier=admin_#{admin.id}" %>
|
@@ -56,7 +56,7 @@ Configuration
|
|
56
56
|
By default, you can switch between Guest and all users in users table, you don't need to do anything. The following is the default configuration.
|
57
57
|
|
58
58
|
SwitchUser.setup do |config|
|
59
|
-
# provider may be :devise, :authlogic or :
|
59
|
+
# provider may be :devise, :authlogic, :restful_authentication or :sorcery
|
60
60
|
config.provider = :devise
|
61
61
|
|
62
62
|
# available_users is a hash,
|
@@ -72,6 +72,21 @@ class SwitchUserController < ApplicationController
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
def sorcery_handle(params)
|
76
|
+
if params[:scope_identifier].blank?
|
77
|
+
self.logout
|
78
|
+
else
|
79
|
+
params[:scope_identifier] =~ /^([^_]+)_(.*)$/
|
80
|
+
scope, identifier = $1, $2
|
81
|
+
|
82
|
+
SwitchUser.available_users.keys.each do |s|
|
83
|
+
if scope == s.to_s && user = find_user(scope, s, identifier)
|
84
|
+
self.auto_login(user)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
75
90
|
def find_user(scope, identifier_scope, identifier)
|
76
91
|
identifier_column = SwitchUser.available_users_identifiers[identifier_scope] || :id
|
77
92
|
if identifier_column == :id
|
@@ -92,4 +107,8 @@ class SwitchUserController < ApplicationController
|
|
92
107
|
def restful_authentication_current_user
|
93
108
|
current_user
|
94
109
|
end
|
110
|
+
|
111
|
+
def sorcery_current_user
|
112
|
+
current_user
|
113
|
+
end
|
95
114
|
end
|
data/lib/switch_user/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: switch_user
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &70238901261280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70238901261280
|
25
25
|
description: Easily switch current user to speed up development
|
26
26
|
email:
|
27
27
|
- flyerhzm@gmail.com
|
@@ -31,7 +31,6 @@ extra_rdoc_files: []
|
|
31
31
|
files:
|
32
32
|
- .gitignore
|
33
33
|
- Gemfile
|
34
|
-
- Gemfile.lock
|
35
34
|
- LICENSE
|
36
35
|
- README.md
|
37
36
|
- Rakefile
|