devise-automaticlogout 0.2.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/app/controllers/automaticlogout_controller.rb +9 -0
- data/app/views/automatic_logout/_timer.html.erb +4 -2
- data/config/routes.rb +1 -2
- data/lib/assets/javascripts/automatic_logout.js +67 -64
- data/lib/devise/automaticlogout/controllers.rb +21 -25
- data/lib/devise/automaticlogout/engine.rb +4 -4
- data/lib/devise/automaticlogout/helpers.rb +3 -3
- data/lib/devise/automaticlogout/version.rb +1 -1
- metadata +21 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7376a12b6138d60c5313dff7b3920fd377680f4158600517f73ae3697d7d08c9
|
4
|
+
data.tar.gz: 252322e067196b1ec2d6ed3d2972a51a510251ab9af83efa380fdf39524e25a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f291157a5b46de703a70cf80cd5c231a9c918bb8652f5c2ac77cd6c9a7bbbc13d0157361900946a74dbdf7da0d51bd14f5e67db21620d54e4101dc4ca7f44249
|
7
|
+
data.tar.gz: 6baba66024afd9be78928af7bcb99ffe7b7c8b7bf536b5d3b14c18cc37b85427096d290546166be2bb05a354bcb8f90b4954881dcde6304bf29a30e746130cdd
|
@@ -1,5 +1,7 @@
|
|
1
1
|
<span class="regressive-timer"
|
2
|
+
style="<%= "display: #{visible ? 'block' : 'none'}" %>"
|
2
3
|
data-visible="<%= visible %>"
|
3
|
-
data-
|
4
|
-
data-
|
4
|
+
data-alert="<%= alert.presence || false %>"
|
5
|
+
data-seconds="<%= session[:devise_autl_seconds] %>"
|
6
|
+
data-message="<%= session[:devise_autl_message] %>">
|
5
7
|
</span>
|
data/config/routes.rb
CHANGED
@@ -2,98 +2,105 @@
|
|
2
2
|
* Module AutomaticLogout for JS Files
|
3
3
|
* @type {[type]}
|
4
4
|
*/
|
5
|
-
|
5
|
+
window.AutomaticLogout = {};
|
6
6
|
|
7
|
-
AutomaticLogout.load = function(){
|
8
|
-
var $regressiveTimer = document.querySelectorAll(
|
9
|
-
|
10
|
-
if(
|
7
|
+
AutomaticLogout.load = function () {
|
8
|
+
var $regressiveTimer = document.querySelectorAll(".regressive-timer")[0];
|
9
|
+
|
10
|
+
if (!!$regressiveTimer && $regressiveTimer.dataset.seconds != "") {
|
11
|
+
console.log("[AutomaticLogout] regressiveTimer started");
|
11
12
|
AutomaticLogout.regressiveTimer();
|
12
13
|
}
|
13
|
-
}
|
14
|
+
};
|
14
15
|
|
15
16
|
/**
|
16
17
|
* Send request for destroy session current_user
|
17
18
|
* @return {[type]} [description]
|
18
19
|
*/
|
19
|
-
AutomaticLogout.destroySession = function(message){
|
20
|
+
AutomaticLogout.destroySession = function (message) {
|
20
21
|
var xhr = new XMLHttpRequest();
|
21
|
-
xhr.open(
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
xhr.open("GET", "/automatic_logout/destroy", true);
|
23
|
+
|
24
|
+
xhr.onload = function () {
|
25
|
+
if (xhr.status == 200) {
|
26
|
+
var $wrapper = document.querySelectorAll(".regressive-timer")[0];
|
27
|
+
|
28
|
+
if ($wrapper && eval($wrapper.dataset.alert) && message) {
|
29
|
+
window.alert(message);
|
30
|
+
}
|
31
|
+
|
32
|
+
return (window.location.href = "/");
|
26
33
|
}
|
27
|
-
}
|
34
|
+
};
|
28
35
|
xhr.send();
|
29
|
-
}
|
36
|
+
};
|
30
37
|
|
31
38
|
/**
|
32
39
|
* Method regressive time based in session auto expired at.
|
33
40
|
* @param {[type]} date_session [description]
|
34
41
|
* @return {[type]} [description]
|
35
42
|
*/
|
36
|
-
AutomaticLogout.regressiveTimer = function(){
|
37
|
-
|
43
|
+
AutomaticLogout.regressiveTimer = function () {
|
38
44
|
/**
|
39
45
|
* Define o que vai ser impresso no DOM.
|
40
|
-
* @param {DOM Object} container
|
41
|
-
* @param {Boolean} visible
|
42
|
-
* @param {String} textContent
|
46
|
+
* @param {DOM Object} container
|
47
|
+
* @param {Boolean} visible
|
48
|
+
* @param {String} textContent
|
43
49
|
*/
|
44
|
-
var visibleTimer = function(container, visible, textContent){
|
45
|
-
if (!visible) visible =
|
46
|
-
if (!textContent) textContent =
|
50
|
+
var visibleTimer = function (container, visible, textContent) {
|
51
|
+
if (!visible) visible = "false";
|
52
|
+
if (!textContent) textContent = "00:00:00";
|
47
53
|
|
48
|
-
if (visible ==
|
49
|
-
return container.textContent = textContent;
|
54
|
+
if (visible == "true") {
|
55
|
+
return (container.textContent = textContent);
|
50
56
|
}
|
51
|
-
}
|
52
|
-
|
57
|
+
};
|
58
|
+
|
53
59
|
/**
|
54
60
|
* Variables used
|
55
61
|
* @param {[type]} '.regressive-timer' [description]
|
56
62
|
* @return {[type]} [description]
|
57
63
|
*/
|
58
|
-
var $regressiveTimer = document.querySelector(
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
visibleTimer(
|
64
|
-
$regressiveTimer,
|
65
|
-
$regressiveTimer.dataset.visible
|
66
|
-
);
|
64
|
+
var $regressiveTimer = document.querySelector(".regressive-timer"),
|
65
|
+
data_message = String($regressiveTimer.dataset.message),
|
66
|
+
data_seconds = Number($regressiveTimer.dataset.seconds),
|
67
|
+
current_time = new Date().getTime();
|
68
|
+
|
69
|
+
visibleTimer($regressiveTimer, $regressiveTimer.dataset.visible);
|
67
70
|
|
68
71
|
var time_expired = new Date();
|
69
72
|
time_expired.setSeconds(time_expired.getSeconds() + data_seconds);
|
70
73
|
|
71
|
-
if (data_seconds != 0 && data_seconds !=
|
72
|
-
var timerDecrement = setInterval(function(){
|
73
|
-
|
74
|
-
|
75
|
-
clearInterval(timerDecrement);
|
74
|
+
if (data_seconds != 0 && data_seconds != "") {
|
75
|
+
var timerDecrement = setInterval(function () {
|
76
|
+
if (data_seconds == 0) {
|
77
|
+
clearInterval(timerDecrement);
|
76
78
|
// limpa a sessão após o ok
|
77
79
|
AutomaticLogout.destroySession(data_message);
|
78
|
-
}else{
|
80
|
+
} else {
|
79
81
|
//tempo descrecente
|
80
82
|
time_expired.setSeconds(time_expired.getSeconds() - 1);
|
81
|
-
|
83
|
+
|
82
84
|
var seconds_integer = (time_expired.getTime() - current_time) / 1000,
|
83
|
-
|
84
|
-
|
85
|
+
date_format = AutomaticLogout.parseDate(seconds_integer),
|
86
|
+
output_date_format =
|
87
|
+
date_format.hours +
|
88
|
+
":" +
|
89
|
+
date_format.minutes +
|
90
|
+
":" +
|
91
|
+
date_format.seconds;
|
85
92
|
|
86
93
|
visibleTimer(
|
87
|
-
$regressiveTimer,
|
88
|
-
$regressiveTimer.dataset.visible,
|
94
|
+
$regressiveTimer,
|
95
|
+
$regressiveTimer.dataset.visible,
|
89
96
|
output_date_format
|
90
97
|
);
|
91
98
|
}
|
92
|
-
|
99
|
+
|
93
100
|
data_seconds -= 1;
|
94
|
-
}, 1000)
|
101
|
+
}, 1000);
|
95
102
|
}
|
96
|
-
}
|
103
|
+
};
|
97
104
|
|
98
105
|
/**
|
99
106
|
* Parse Date
|
@@ -105,12 +112,8 @@ AutomaticLogout.regressiveTimer = function(){
|
|
105
112
|
* seconds: seconds
|
106
113
|
* }
|
107
114
|
*/
|
108
|
-
AutomaticLogout.parseDate = function(seconds_float){
|
109
|
-
|
110
|
-
var days,
|
111
|
-
hours,
|
112
|
-
minutes,
|
113
|
-
seconds;
|
115
|
+
AutomaticLogout.parseDate = function (seconds_float) {
|
116
|
+
var days, hours, minutes, seconds;
|
114
117
|
|
115
118
|
days = parseInt(seconds_float / 86400);
|
116
119
|
seconds_float = seconds_float % 86400;
|
@@ -121,24 +124,24 @@ AutomaticLogout.parseDate = function(seconds_float){
|
|
121
124
|
minutes = parseInt(seconds_float / 60);
|
122
125
|
seconds = parseInt(seconds_float % 60);
|
123
126
|
|
124
|
-
if(hours < 10){
|
125
|
-
hours = "0"+hours;
|
127
|
+
if (hours < 10) {
|
128
|
+
hours = "0" + hours;
|
126
129
|
hours = hours.substr(0, 2);
|
127
130
|
}
|
128
131
|
|
129
|
-
if(minutes < 10){
|
130
|
-
minutes = "0"+minutes;
|
132
|
+
if (minutes < 10) {
|
133
|
+
minutes = "0" + minutes;
|
131
134
|
minutes = minutes.substr(0, 2);
|
132
135
|
}
|
133
136
|
|
134
|
-
if(seconds <=9){
|
135
|
-
seconds = "0"+seconds;
|
137
|
+
if (seconds <= 9) {
|
138
|
+
seconds = "0" + seconds;
|
136
139
|
}
|
137
140
|
|
138
141
|
return {
|
139
142
|
days: days,
|
140
143
|
hours: hours,
|
141
144
|
minutes: minutes,
|
142
|
-
seconds: seconds
|
143
|
-
}
|
144
|
-
}
|
145
|
+
seconds: seconds,
|
146
|
+
};
|
147
|
+
};
|
@@ -1,34 +1,30 @@
|
|
1
1
|
module Devise
|
2
|
-
module
|
2
|
+
module Automaticlogout
|
3
3
|
module Controllers
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
7
|
-
::ApplicationController.before_action do |c|
|
8
|
-
if current_user.present?
|
9
|
-
key_classify = Devise.mappings.keys.first
|
10
|
-
resource_name = Devise.mappings[key_classify].class_name.to_s
|
11
|
-
# get instance for class using devise
|
12
|
-
c.session[:seconds] = resource_name.classify.constantize.timeout_in.seconds.to_i
|
13
|
-
# I18n.t devise.automaticlogout.message
|
14
|
-
c.session[:message] = I18n.t 'devise.automaticlogout.message' || 'Session expired!'
|
15
|
-
end
|
6
|
+
DEFAULT_MESSAGE = 'Session expired! You will be redirect.'.freeze
|
16
7
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
8
|
+
module ClassMethods
|
9
|
+
def devise_automatic_logout(options = {})
|
10
|
+
prepend_before_action do |c|
|
11
|
+
time = options.fetch(:time, nil)
|
12
|
+
message = options.fetch(:message, DEFAULT_MESSAGE)
|
13
|
+
scope = options.fetch(:scope, 'user')
|
14
|
+
|
15
|
+
seconds = if time&.positive?
|
16
|
+
time
|
17
|
+
else
|
18
|
+
mapping = Devise.mappings[scope.to_sym]
|
19
|
+
return unless mapping
|
20
|
+
|
21
|
+
mapping.to.timeout_in.seconds.to_i
|
22
|
+
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
reset_session
|
31
|
-
redirect_to '/', notice: session[:message]
|
24
|
+
if seconds
|
25
|
+
c.session[:devise_autl_message] = message
|
26
|
+
c.session[:devise_autl_seconds] = seconds
|
27
|
+
end
|
32
28
|
end
|
33
29
|
end
|
34
30
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module Devise
|
2
|
-
module
|
2
|
+
module Automaticlogout
|
3
3
|
class Engine < ::Rails::Engine
|
4
|
-
|
4
|
+
engine_name 'devise_automaticlogout'
|
5
5
|
|
6
6
|
ActiveSupport.on_load :action_controller do
|
7
|
-
include Devise::
|
7
|
+
include Devise::Automaticlogout::Controllers
|
8
8
|
end
|
9
9
|
|
10
10
|
ActiveSupport.on_load :action_view do
|
11
|
-
include Devise::
|
11
|
+
include Devise::Automaticlogout::Helpers
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Devise
|
2
|
-
module
|
2
|
+
module Automaticlogout
|
3
3
|
module Helpers
|
4
|
-
def regressive_timer(visible: false)
|
5
|
-
render 'automatic_logout/timer', visible: visible
|
4
|
+
def regressive_timer(visible: false, alert: false)
|
5
|
+
render 'automatic_logout/timer', visible: visible, alert: alert
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-automaticlogout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thadeu Esteves Jr
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: devise
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rubocop
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Provides automatic session timeout in a Rails Devise application.
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- MIT-LICENSE
|
77
77
|
- README.md
|
78
78
|
- Rakefile
|
79
|
+
- app/controllers/automaticlogout_controller.rb
|
79
80
|
- app/views/automatic_logout/_timer.html.erb
|
80
81
|
- config/routes.rb
|
81
82
|
- lib/assets/javascripts/automatic_logout.js
|
@@ -88,11 +89,11 @@ files:
|
|
88
89
|
- lib/devise/automaticlogout/engine.rb
|
89
90
|
- lib/devise/automaticlogout/helpers.rb
|
90
91
|
- lib/devise/automaticlogout/version.rb
|
91
|
-
homepage: https://github.com/
|
92
|
+
homepage: https://github.com/thadeu/devise-automaticlogout
|
92
93
|
licenses:
|
93
94
|
- MIT
|
94
95
|
metadata: {}
|
95
|
-
post_install_message:
|
96
|
+
post_install_message:
|
96
97
|
rdoc_options: []
|
97
98
|
require_paths:
|
98
99
|
- lib
|
@@ -107,9 +108,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
108
|
- !ruby/object:Gem::Version
|
108
109
|
version: '0'
|
109
110
|
requirements: []
|
110
|
-
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
112
|
-
signing_key:
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.7.6
|
113
|
+
signing_key:
|
113
114
|
specification_version: 4
|
114
115
|
summary: Provides automatic session timeout in a Rails Devise application.
|
115
116
|
test_files: []
|