rodauth-become_account 0.2.1-jruby
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +100 -0
- data/lib/rodauth/features/become_account.rb +36 -0
- metadata +213 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e88d2e9232d1f0f7cda79e3f9a96ce89161448db
|
4
|
+
data.tar.gz: f8e5b9a6a3cb66ca8d50cafef1796acf8fc63219
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 676b3e29197247523bc9970cc8870701b241ce035dcbefedd8886f1065ce85dab34b70dbeaba35c68c7bdc2eb4b13c60895853ea37154126cacfd2253a2829ae
|
7
|
+
data.tar.gz: 8f31025150728da04577d459c08550b65786990786028274ca70699fa0eb20e6bdc666584b384823b05005e9bbe144a31c57df657a54dfa3b430c8cbfdc47800
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Become Account feature for Rodauth
|
2
|
+
|
3
|
+
This Rodauth feature allows you to easily switch into another Rodauth account,
|
4
|
+
without requiring that specific accounts password.
|
5
|
+
|
6
|
+
A nice bonus is that it remembers your original account, so when you log out of
|
7
|
+
the temporary account, you're logged back in as you.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "rodauth-become_account"
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install rodauth-become_account
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
To use the become account feature requires two steps.
|
28
|
+
|
29
|
+
The first is to enable the feature:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
class App < Roda
|
33
|
+
plugin :rodauth do
|
34
|
+
enable :become_account
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
And the second is to setup a route to become an account:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
class App < Roda
|
43
|
+
plugin :rodauth do
|
44
|
+
enable :become_account
|
45
|
+
end
|
46
|
+
|
47
|
+
route do |r|
|
48
|
+
r.is "become", :id do |id|
|
49
|
+
# Authenticate the request to allow this action.
|
50
|
+
#
|
51
|
+
# Can be done multiple ways. For this example, we're just going to allow
|
52
|
+
# all become_account actions if running in development mode.
|
53
|
+
#
|
54
|
+
# You want to ensure you protect this route somehow.
|
55
|
+
if ENV["RACK_ENV"] != "development"
|
56
|
+
r.halt([401, { "Content-Type" => "text/html" }, ["Access denied"]])
|
57
|
+
end
|
58
|
+
|
59
|
+
# Perform your account lookup.
|
60
|
+
account = DB[:accounts][id: id.to_i]
|
61
|
+
|
62
|
+
# Optional.
|
63
|
+
flash[:notice] = "You've successfully became #{account[:email]}"
|
64
|
+
|
65
|
+
# Switch accounts using the become_account feature.
|
66
|
+
rodauth.become_account(account)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
## Edgecases
|
73
|
+
|
74
|
+
It's possible that 2-factor authentication will cause issues becoming users who
|
75
|
+
have that feature enabled. If you experience that issue, open a discussion so
|
76
|
+
we can possibly work around it.
|
77
|
+
|
78
|
+
## Where's my routes?
|
79
|
+
|
80
|
+
Most of Rodauth's features enable routes by default, allowing you to get up and
|
81
|
+
running immediately. I wanted to do that with this feature, but I didn't want to
|
82
|
+
risk exposing a feature to become any-account without any forethought.
|
83
|
+
|
84
|
+
So with that said, you need to implement your own route that allows an account
|
85
|
+
to become another account.
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/adam12/rodauth-become_account.
|
90
|
+
|
91
|
+
I love pull requests! If you fork this project and modify it, please ping me to see
|
92
|
+
if your changes can be incorporated back into this project.
|
93
|
+
|
94
|
+
That said, if your feature idea is nontrivial, you should probably open an issue to
|
95
|
+
[discuss it](http://www.igvita.com/2011/12/19/dont-push-your-pull-requests/)
|
96
|
+
before attempting a pull request.
|
97
|
+
|
98
|
+
## License
|
99
|
+
|
100
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Rodauth
|
3
|
+
Feature.define(:become_account) do
|
4
|
+
depends :login, :logout
|
5
|
+
|
6
|
+
auth_value_method :previous_session_key, :previous_account_id
|
7
|
+
|
8
|
+
def logout_redirect
|
9
|
+
return login_redirect if session[session_key]
|
10
|
+
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def become_account(account)
|
15
|
+
session[previous_session_key] = session[session_key]
|
16
|
+
account_from_login(account[login_column])
|
17
|
+
update_session
|
18
|
+
end
|
19
|
+
|
20
|
+
def update_session
|
21
|
+
previous_session_value = session[previous_session_key]
|
22
|
+
|
23
|
+
super
|
24
|
+
|
25
|
+
session[previous_session_key] = previous_session_value if previous_session_value
|
26
|
+
end
|
27
|
+
|
28
|
+
def clear_session
|
29
|
+
previous_session_value = session[previous_session_key]
|
30
|
+
|
31
|
+
super
|
32
|
+
|
33
|
+
session[session_key] = previous_session_value if previous_session_value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rodauth-become_account
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: jruby
|
6
|
+
authors:
|
7
|
+
- Adam Daniels
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.10'
|
19
|
+
name: rodauth
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
name: roda
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '5.0'
|
47
|
+
name: minitest
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
name: rake
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0.2'
|
75
|
+
name: rubygems-tasks
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0.6'
|
89
|
+
name: rack-test
|
90
|
+
prerelease: false
|
91
|
+
type: :development
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '2.0'
|
103
|
+
name: tilt
|
104
|
+
prerelease: false
|
105
|
+
type: :development
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
name: rack_csrf
|
118
|
+
prerelease: false
|
119
|
+
type: :development
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
name: bcrypt
|
132
|
+
prerelease: false
|
133
|
+
type: :development
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
name: sequel
|
146
|
+
prerelease: false
|
147
|
+
type: :development
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
requirement: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
name: capybara
|
160
|
+
prerelease: false
|
161
|
+
type: :development
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
requirement: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
name: jdbc-sqlite3
|
174
|
+
prerelease: false
|
175
|
+
type: :development
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description:
|
182
|
+
email: adam@mediadrive.ca
|
183
|
+
executables: []
|
184
|
+
extensions: []
|
185
|
+
extra_rdoc_files: []
|
186
|
+
files:
|
187
|
+
- README.md
|
188
|
+
- lib/rodauth/features/become_account.rb
|
189
|
+
homepage: https://github.com/adam12/rodauth-become_account
|
190
|
+
licenses:
|
191
|
+
- MIT
|
192
|
+
metadata: {}
|
193
|
+
post_install_message:
|
194
|
+
rdoc_options: []
|
195
|
+
require_paths:
|
196
|
+
- lib
|
197
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
requirements: []
|
208
|
+
rubyforge_project:
|
209
|
+
rubygems_version: 2.6.8
|
210
|
+
signing_key:
|
211
|
+
specification_version: 4
|
212
|
+
summary: Easily switch Rodauth accounts
|
213
|
+
test_files: []
|