auto-session-timeout 0.9.7 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +15 -10
- data/CHANGELOG +4 -0
- data/README.md +58 -26
- data/lib/auto/session/timeout/version.rb +1 -1
- data/lib/auto_session_timeout.rb +5 -1
- data/test/auto_session_timeout_helper_test.rb +9 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71d3e9f467963b89be2bdfb4e87ce915ed693536fd0760cf954d6116c8987c3a
|
4
|
+
data.tar.gz: f3b2cfee583099d5bb29400db0e4e187f8fdfd1750cc12cfc45380316719df50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20685219ebb5e6750e215d8a873ad60b7de0a3e05f36c9bfb03249266b4886b240ea6b009242a718dc7d91b723053d3c5c3a2ae4f768b6ab016cefe915d7ed73
|
7
|
+
data.tar.gz: d94594ce6b6d7464ad543fcad88e8343e53b1d3a1f6af02f0d6d24a2877167b6cd776a4e62f575cc023ee752a30be4b7ed518b0283ed6eb144b42a5345d2705c
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -2,13 +2,12 @@ sudo: false
|
|
2
2
|
language: ruby
|
3
3
|
cache: bundler
|
4
4
|
before_install:
|
5
|
-
- gem
|
6
|
-
- gem install bundler -v '< 2'
|
5
|
+
- gem install bundler -v '~> 2'
|
7
6
|
rvm:
|
8
|
-
- 2.4.
|
9
|
-
- 2.5.
|
10
|
-
- 2.6.
|
11
|
-
- 2.7.
|
7
|
+
- 2.4.10
|
8
|
+
- 2.5.8
|
9
|
+
- 2.6.6
|
10
|
+
- 2.7.2
|
12
11
|
- ruby-head
|
13
12
|
env:
|
14
13
|
- RAILS_VERSION='~> 3.2'
|
@@ -18,15 +17,21 @@ env:
|
|
18
17
|
- RAILS_VERSION='~> 5.0'
|
19
18
|
- RAILS_VERSION='~> 5.1'
|
20
19
|
- RAILS_VERSION='~> 5.2'
|
20
|
+
- RAILS_VERSION='~> 6.0'
|
21
|
+
- RAILS_VERSION='~> 6.1'
|
21
22
|
jobs:
|
22
23
|
exclude:
|
23
|
-
- rvm: 2.
|
24
|
+
- rvm: 2.4.10
|
25
|
+
env: RAILS_VERSION='~> 6.0'
|
26
|
+
- rvm: 2.4.10
|
27
|
+
env: RAILS_VERSION='~> 6.1'
|
28
|
+
- rvm: 2.7.2
|
24
29
|
env: RAILS_VERSION='~> 3.2'
|
25
|
-
- rvm: 2.7.
|
30
|
+
- rvm: 2.7.2
|
26
31
|
env: RAILS_VERSION='~> 4.0'
|
27
|
-
- rvm: 2.7.
|
32
|
+
- rvm: 2.7.2
|
28
33
|
env: RAILS_VERSION='~> 4.1'
|
29
|
-
- rvm: 2.7.
|
34
|
+
- rvm: 2.7.2
|
30
35
|
env: RAILS_VERSION='~> 4.2'
|
31
36
|
- rvm: ruby-head
|
32
37
|
env: RAILS_VERSION='~> 3.2'
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -18,11 +18,15 @@ gem 'auto-session-timeout'
|
|
18
18
|
|
19
19
|
And then execute:
|
20
20
|
|
21
|
-
|
21
|
+
```
|
22
|
+
$ bundle
|
23
|
+
```
|
22
24
|
|
23
25
|
Or install it yourself as:
|
24
26
|
|
25
|
-
|
27
|
+
```
|
28
|
+
$ gem install auto-session-timeout
|
29
|
+
```
|
26
30
|
|
27
31
|
## Usage
|
28
32
|
|
@@ -31,14 +35,15 @@ After installing, tell your application controller to use auto timeout:
|
|
31
35
|
```ruby
|
32
36
|
class ApplicationController < ActionController::Base
|
33
37
|
auto_session_timeout 1.hour
|
34
|
-
...
|
35
38
|
end
|
36
39
|
```
|
37
40
|
|
38
|
-
This will use a global timeout of 1 hour.
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
This will use a global timeout of 1 hour. The gem assumes your authentication
|
42
|
+
provider has a `#current_user` method that returns the currently logged in user.
|
43
|
+
|
44
|
+
If you want to specify a custom timeout value per user, don't pass a value to
|
45
|
+
the controller as shown above. Instead, override `#auto_timeout` in your
|
46
|
+
`#current_user` model. This is typically the `User` class:
|
42
47
|
|
43
48
|
```ruby
|
44
49
|
class ApplicationController < ActionController::Base
|
@@ -86,7 +91,7 @@ actions entirely with your own custom code:
|
|
86
91
|
```ruby
|
87
92
|
class SessionsController < ApplicationController
|
88
93
|
def active
|
89
|
-
|
94
|
+
render_session_status
|
90
95
|
end
|
91
96
|
|
92
97
|
def timeout
|
@@ -99,13 +104,50 @@ In any of these cases, make sure to properly map the actions in your
|
|
99
104
|
routes.rb file:
|
100
105
|
|
101
106
|
```ruby
|
102
|
-
get
|
103
|
-
get
|
107
|
+
get "active", to: "sessions#active"
|
108
|
+
get "timeout", to: "sessions#timeout"
|
104
109
|
```
|
105
110
|
|
106
111
|
You're done! Enjoy watching your sessions automatically timeout.
|
107
112
|
|
108
|
-
##
|
113
|
+
## Using with Devise
|
114
|
+
|
115
|
+
When using Devise for authentication you will need to add a scoped
|
116
|
+
sessions controller and call the timeout actions helper there.
|
117
|
+
For example:
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
class Users::SessionsController < Devise::SessionsController
|
121
|
+
auto_session_timeout_actions
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
In your routes.rb file you will need to declare your scoped controller
|
126
|
+
and declare the timeout actions inside the same Devise scope:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
Rails.application.routes.draw do
|
130
|
+
devise_for :users, controllers: { sessions: "users/sessions" }
|
131
|
+
|
132
|
+
devise_scope :user do
|
133
|
+
get "active", to: "users/sessions#active"
|
134
|
+
get "timeout", to: "users/sessions#timeout"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
139
|
+
You can use Devise's `#user_signed_in?` method when you call the JS helper
|
140
|
+
method in your view:
|
141
|
+
|
142
|
+
```erb
|
143
|
+
<body>
|
144
|
+
<% if user_signed_in? %>
|
145
|
+
<%= auto_session_timeout_js %>
|
146
|
+
<% end %>
|
147
|
+
</body>
|
148
|
+
```
|
149
|
+
|
150
|
+
## Optional Configuration
|
109
151
|
|
110
152
|
By default, the JavaScript code checks the server every 60 seconds for
|
111
153
|
active sessions. If you prefer that it check more frequently, pass a
|
@@ -113,23 +155,13 @@ frequency attribute to the helper method. The frequency is given in
|
|
113
155
|
seconds. The following example checks the server every 15 seconds:
|
114
156
|
|
115
157
|
```erb
|
116
|
-
<
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
<% end %>
|
122
|
-
...
|
123
|
-
</body>
|
124
|
-
</html>
|
158
|
+
<body>
|
159
|
+
<% if current_user %>
|
160
|
+
<%= auto_session_timeout_js frequency: 15 %>
|
161
|
+
<% end %>
|
162
|
+
</body>
|
125
163
|
```
|
126
164
|
|
127
|
-
## TODO
|
128
|
-
|
129
|
-
* current_user must be defined
|
130
|
-
* using Prototype vs. jQuery
|
131
|
-
* using with Devise
|
132
|
-
|
133
165
|
## Contributing
|
134
166
|
|
135
167
|
1. Fork it
|
data/lib/auto_session_timeout.rb
CHANGED
@@ -9,7 +9,7 @@ module AutoSessionTimeout
|
|
9
9
|
protect_from_forgery except: [:active, :timeout]
|
10
10
|
prepend_before_action do |c|
|
11
11
|
if session_expired?(c) && !signing_in?(c)
|
12
|
-
c
|
12
|
+
handle_session_reset(c)
|
13
13
|
else
|
14
14
|
unless c.request.original_url.start_with?(c.send(:active_url))
|
15
15
|
offset = seconds || (current_user.respond_to?(:auto_timeout) ? current_user.auto_timeout : nil)
|
@@ -37,6 +37,10 @@ module AutoSessionTimeout
|
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
+
def handle_session_reset(c)
|
41
|
+
c.send :reset_session
|
42
|
+
end
|
43
|
+
|
40
44
|
def signing_in?(c)
|
41
45
|
c.request.env["PATH_INFO"] == sign_in_path && c.request.env["REQUEST_METHOD"] == "POST"
|
42
46
|
end
|
@@ -2,17 +2,21 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
describe AutoSessionTimeoutHelper do
|
4
4
|
|
5
|
-
class
|
5
|
+
class StubView
|
6
|
+
include AutoSessionTimeoutHelper
|
7
|
+
include ActionView::Helpers::JavaScriptHelper
|
8
|
+
include ActionView::Helpers::TagHelper
|
9
|
+
|
6
10
|
def timeout_path
|
7
|
-
|
11
|
+
"/timeout"
|
8
12
|
end
|
9
|
-
|
13
|
+
|
10
14
|
def active_path
|
11
|
-
|
15
|
+
"/active"
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
15
|
-
subject {
|
19
|
+
subject { StubView.new }
|
16
20
|
|
17
21
|
describe "#auto_session_timeout_js" do
|
18
22
|
it "returns correct JS" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto-session-timeout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Bass
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
123
|
+
rubygems_version: 3.2.22
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: Provides automatic session timeout in a Rails application.
|