auto-session-timeout 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc498b02e7b05cbf09f3af63eb7f83617970fa76287e7beb522e2b676df6c6a0
4
- data.tar.gz: fad257ffc2872343879ab12346d6d029c5df75e3ec7eb0913e61f441afa5250b
3
+ metadata.gz: 71d3e9f467963b89be2bdfb4e87ce915ed693536fd0760cf954d6116c8987c3a
4
+ data.tar.gz: f3b2cfee583099d5bb29400db0e4e187f8fdfd1750cc12cfc45380316719df50
5
5
  SHA512:
6
- metadata.gz: 58db2799f2c39e9f4107bbdd21b95a563786e5e1bed28670ff0f0d04d86596c0690846a8d07c71b92804d584a40704295539b06115e52eb538a4f5693f20152a
7
- data.tar.gz: 0ba4a07545611dd012b465e9f21eb6768de9dd588ef4c9bb2c1815bc3253bab062c360443b088c5083cfc524b0e563193edaa86307ba00f8078f4d9064eaabb6
6
+ metadata.gz: 20685219ebb5e6750e215d8a873ad60b7de0a3e05f36c9bfb03249266b4886b240ea6b009242a718dc7d91b723053d3c5c3a2ae4f768b6ab016cefe915d7ed73
7
+ data.tar.gz: d94594ce6b6d7464ad543fcad88e8343e53b1d3a1f6af02f0d6d24a2877167b6cd776a4e62f575cc023ee752a30be4b7ed518b0283ed6eb144b42a5345d2705c
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  .yardoc
6
6
  *.sublime-project
7
7
  *.sublime-workspace
8
+ .idea
8
9
  Gemfile.lock
9
10
  InstalledFiles
10
11
  _yardoc
data/.travis.yml CHANGED
@@ -2,13 +2,12 @@ sudo: false
2
2
  language: ruby
3
3
  cache: bundler
4
4
  before_install:
5
- - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
6
- - gem install bundler -v '< 2'
5
+ - gem install bundler -v '~> 2'
7
6
  rvm:
8
- - 2.4.9
9
- - 2.5.7
10
- - 2.6.5
11
- - 2.7.0
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.7.0
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.0
30
+ - rvm: 2.7.2
26
31
  env: RAILS_VERSION='~> 4.0'
27
- - rvm: 2.7.0
32
+ - rvm: 2.7.2
28
33
  env: RAILS_VERSION='~> 4.1'
29
- - rvm: 2.7.0
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
@@ -1,3 +1,7 @@
1
+ 2021-10-11 - v0.9.8
2
+
3
+ 2021-10-10 - Custom session timeout method [JunaidUK]
4
+
1
5
  2021-02-02 - v0.9.7
2
6
 
3
7
  2021-02-02 - Rails 6 compatibility [jasonheecs]
data/README.md CHANGED
@@ -18,11 +18,15 @@ gem 'auto-session-timeout'
18
18
 
19
19
  And then execute:
20
20
 
21
- $ bundle
21
+ ```
22
+ $ bundle
23
+ ```
22
24
 
23
25
  Or install it yourself as:
24
26
 
25
- $ gem install auto-session-timeout
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. If you want to specify a
39
- custom timeout value per user, don't pass a value above. Instead,
40
- override `#auto_timeout` in your `#current_user` model. This is
41
- typically the `User` class:
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
- render_session_status
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 'active' => 'sessions#active'
103
- get 'timeout' => 'sessions#timeout'
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
- ## Additional Configuration
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
- <html>
117
- <head>...</head>
118
- <body>
119
- <% if current_user %>
120
- <%= auto_session_timeout_js frequency: 15 %>
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
@@ -1,7 +1,7 @@
1
1
  module Auto
2
2
  module Session
3
3
  module Timeout
4
- VERSION = "0.9.7"
4
+ VERSION = "0.9.8"
5
5
  end
6
6
  end
7
7
  end
@@ -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.send :reset_session
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 ActionView::Base
5
+ class StubView
6
+ include AutoSessionTimeoutHelper
7
+ include ActionView::Helpers::JavaScriptHelper
8
+ include ActionView::Helpers::TagHelper
9
+
6
10
  def timeout_path
7
- '/timeout'
11
+ "/timeout"
8
12
  end
9
-
13
+
10
14
  def active_path
11
- '/active'
15
+ "/active"
12
16
  end
13
17
  end
14
18
 
15
- subject { ActionView::Base.new }
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.7
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-02-02 00:00:00.000000000 Z
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.1.4
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.