session-check 0.2.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/session/check/session_checks_controller.rb +44 -0
- data/app/helpers/session/check/session_check_helper.rb +21 -0
- data/config/routes.rb +3 -1
- data/lib/session/check/engine.rb +4 -3
- data/lib/session/check/version.rb +3 -1
- metadata +90 -6
- data/app/controllers/session_checks_controller.rb +0 -23
- data/app/helpers/session_check_helper.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 102b701a51a977e38686014696f35e3e81b3ceee97708b5f691d90d28ecad97d
|
4
|
+
data.tar.gz: ad91cd99529a77334b30236055c7f2afbe922c23b896df37ae2c7917625ba4a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78245fe80da9ef0b41f55c1474a2a58724eb6e0470a1361980fba862798b269c1faee4a55c1e34b4118ef259d724ee26a2af975cfe8693dbf046f53fbfbe7622
|
7
|
+
data.tar.gz: f9d02adc30f194bb6c53fc0011f54892963a82b8b8e8b965028ba4bbc52671e1ba92c59dc963399017dfef7a9119ab0d3f1516b5ce09a83c9b9f9b5c29561579
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Session
|
4
|
+
module Check
|
5
|
+
class SessionChecksController < ActionController::Base
|
6
|
+
skip_authorization_check if defined?(CanCan)
|
7
|
+
|
8
|
+
prepend_before_action :dont_update_request_time
|
9
|
+
|
10
|
+
# Find it there is a session, and if it has any warden information. If so, the user is logged in.
|
11
|
+
def time_to_session_expiry
|
12
|
+
session_exists = false
|
13
|
+
session_expires_in = 0
|
14
|
+
if current_user
|
15
|
+
session_exists = true
|
16
|
+
# This calculates how many seconds there are until they are logged out
|
17
|
+
session_expires_in = calculate_session_expires_in
|
18
|
+
end
|
19
|
+
render json: { session_exists: session_exists, session_expires_in: session_expires_in }
|
20
|
+
end
|
21
|
+
|
22
|
+
# This ensures this request ping doesn't update their last access time.
|
23
|
+
private def dont_update_request_time
|
24
|
+
request.env['devise.skip_trackable'] = true
|
25
|
+
end
|
26
|
+
|
27
|
+
private def calculate_session_expires_in
|
28
|
+
User.timeout_in -
|
29
|
+
Time.now.utc.to_i.seconds +
|
30
|
+
SessionChecksController.time_of_last_warden_request(session).to_i.seconds
|
31
|
+
rescue => _e
|
32
|
+
1000000.seconds
|
33
|
+
end
|
34
|
+
|
35
|
+
class << self
|
36
|
+
def time_of_last_warden_request(session)
|
37
|
+
session['warden.user.user.session']['last_request_at']
|
38
|
+
rescue => _e
|
39
|
+
Time.zone.now
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'devise'
|
4
|
+
|
5
|
+
module Session
|
6
|
+
module Check
|
7
|
+
module SessionCheckHelper
|
8
|
+
def session_check(options = {})
|
9
|
+
locals = {
|
10
|
+
session_time: Devise.timeout_in,
|
11
|
+
check_every: 10,
|
12
|
+
reset_counter_on_ajax: true,
|
13
|
+
logged_out_url: '/users/sign_in',
|
14
|
+
current_user: current_user
|
15
|
+
}.merge options
|
16
|
+
|
17
|
+
ActionController::Base.render(partial: '/session_check', locals: locals)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/config/routes.rb
CHANGED
data/lib/session/check/engine.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails'
|
2
4
|
|
3
5
|
module Session
|
4
6
|
module Check
|
5
7
|
class Engine < ::Rails::Engine
|
6
|
-
|
8
|
+
config.to_prepare do
|
7
9
|
ActiveSupport.on_load :action_controller do
|
8
|
-
|
10
|
+
include Session::Check::SessionCheckHelper
|
9
11
|
helper_method :session_check
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
15
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: session-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Lascelles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,90 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: combustion
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: timecop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
41
125
|
description:
|
42
126
|
email:
|
43
127
|
- harry@harrylascelles.com
|
@@ -46,15 +130,15 @@ extensions: []
|
|
46
130
|
extra_rdoc_files: []
|
47
131
|
files:
|
48
132
|
- README.md
|
49
|
-
- app/controllers/session_checks_controller.rb
|
50
|
-
- app/helpers/session_check_helper.rb
|
133
|
+
- app/controllers/session/check/session_checks_controller.rb
|
134
|
+
- app/helpers/session/check/session_check_helper.rb
|
51
135
|
- app/views/_session_check.html.erb
|
52
136
|
- config/routes.rb
|
53
137
|
- lib/session-check.rb
|
54
138
|
- lib/session/check.rb
|
55
139
|
- lib/session/check/engine.rb
|
56
140
|
- lib/session/check/version.rb
|
57
|
-
homepage: https://github.com/
|
141
|
+
homepage: https://github.com/bambooengineering/session-check
|
58
142
|
licenses:
|
59
143
|
- MIT
|
60
144
|
metadata: {}
|
@@ -73,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
157
|
- !ruby/object:Gem::Version
|
74
158
|
version: '0'
|
75
159
|
requirements: []
|
76
|
-
rubygems_version: 3.
|
160
|
+
rubygems_version: 3.1.6
|
77
161
|
signing_key:
|
78
162
|
specification_version: 4
|
79
163
|
summary: A gem for JS clients to check if their session has expired.
|
@@ -1,23 +0,0 @@
|
|
1
|
-
class SessionChecksController < ActionController::Base
|
2
|
-
|
3
|
-
skip_authorization_check if defined?(CanCan)
|
4
|
-
|
5
|
-
prepend_before_action :dont_update_request_time
|
6
|
-
|
7
|
-
# Find it there is a session, and if it has any warden information. If so, the user is logged in.
|
8
|
-
def time_to_session_expiry
|
9
|
-
session_exists = false
|
10
|
-
session_expires_in = 0
|
11
|
-
if current_user
|
12
|
-
session_exists = true
|
13
|
-
# This calculates how many seconds there are until they are logged out
|
14
|
-
session_expires_in = User.timeout_in - Time.now.utc.to_i + session['warden.user.user.session']['last_request_at'].to_i rescue 1000000
|
15
|
-
end
|
16
|
-
render json: {session_exists: session_exists, session_expires_in: session_expires_in}
|
17
|
-
end
|
18
|
-
|
19
|
-
# This ensures this request ping doesn't update their last access time.
|
20
|
-
def dont_update_request_time
|
21
|
-
request.env['devise.skip_trackable'] = true
|
22
|
-
end
|
23
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'devise'
|
2
|
-
|
3
|
-
module SessionCheckHelper
|
4
|
-
|
5
|
-
def session_check(options = {})
|
6
|
-
locals = {
|
7
|
-
session_time: Devise.timeout_in,
|
8
|
-
check_every: 10,
|
9
|
-
reset_counter_on_ajax: true,
|
10
|
-
logged_out_url: '/users/sign_in'
|
11
|
-
}.merge options
|
12
|
-
render :partial => '/session_check', locals: locals
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|