devise-automaticlogout 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/views/automatic_logout/_timer.html.erb +3 -2
- data/lib/assets/javascripts/automatic_logout.js +53 -60
- data/lib/assets/javascripts/automatic_logout/classic.js +4 -0
- data/lib/assets/javascripts/automatic_logout/jquery.js +4 -0
- data/lib/assets/javascripts/automatic_logout/turbolinks-classic.js +5 -0
- data/lib/assets/javascripts/automatic_logout/turbolinks.js +5 -0
- data/lib/devise/automaticlogout/controllers.rb +15 -15
- data/lib/devise/automaticlogout/helpers.rb +2 -2
- data/lib/devise/automaticlogout/version.rb +1 -1
- metadata +14 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52ed5da827aea06f7e10d00f5cbf2a07b19e1a76
|
4
|
+
data.tar.gz: ee85c8798fc12f20d89a33d421cc7321ddb58dd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd92b4c4e1e6ff1fa0b5eae7d194e7b88d9c90ffc34a0a1f309ecdf93c4cdb57df272ccbcf6ec3bec30cda7fd63d806b46f5165d72e67ddd7e96e6c9efb4bf9b
|
7
|
+
data.tar.gz: 0054de9eb567ae6567b4635e7847302a5c51bf8ecec1037d84f581e4a7bc82c39708206e0782a31c01b0e05fe4d8a55fe2299008ab4322c42e71540ea8ba630b
|
@@ -4,22 +4,28 @@
|
|
4
4
|
*/
|
5
5
|
var AutomaticLogout = AutomaticLogout || {};
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
: AutomaticLogout.ajaxSessionTimeout();
|
15
|
-
});
|
7
|
+
AutomaticLogout.load = function(){
|
8
|
+
var $regressiveTimer = document.querySelectorAll('.regressive-timer')[0];
|
9
|
+
|
10
|
+
if((!!$regressiveTimer) && ($regressiveTimer.dataset.seconds != '')){
|
11
|
+
AutomaticLogout.regressiveTimer();
|
12
|
+
}
|
13
|
+
}
|
16
14
|
|
17
15
|
/**
|
18
16
|
* Send request for destroy session current_user
|
19
17
|
* @return {[type]} [description]
|
20
18
|
*/
|
21
|
-
AutomaticLogout.destroySession = function(){
|
22
|
-
|
19
|
+
AutomaticLogout.destroySession = function(message){
|
20
|
+
var xhr = new XMLHttpRequest();
|
21
|
+
xhr.open('GET','/devise/automatic_logout/destroy', true);
|
22
|
+
xhr.onload = function(){
|
23
|
+
if(xhr.status == 200){
|
24
|
+
if(message) alert(message)
|
25
|
+
return window.location.href = '/';
|
26
|
+
}
|
27
|
+
}
|
28
|
+
xhr.send();
|
23
29
|
}
|
24
30
|
|
25
31
|
/**
|
@@ -27,15 +33,37 @@ AutomaticLogout.destroySession = function(){
|
|
27
33
|
* @param {[type]} date_session [description]
|
28
34
|
* @return {[type]} [description]
|
29
35
|
*/
|
30
|
-
AutomaticLogout.regressiveTimer = function(){
|
36
|
+
AutomaticLogout.regressiveTimer = function(){
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Define o que vai ser impresso no DOM.
|
40
|
+
* @param {DOM Object} container
|
41
|
+
* @param {Boolean} visible
|
42
|
+
* @param {String} textContent
|
43
|
+
*/
|
44
|
+
var visibleTimer = function(container, visible, textContent){
|
45
|
+
if (!visible) visible = 'false';
|
46
|
+
if (!textContent) textContent = '00:00:00';
|
47
|
+
|
48
|
+
if (visible == 'true'){
|
49
|
+
return container.textContent = textContent;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
31
53
|
/**
|
32
54
|
* Variables used
|
33
55
|
* @param {[type]} '.regressive-timer' [description]
|
34
56
|
* @return {[type]} [description]
|
35
57
|
*/
|
36
|
-
var
|
37
|
-
|
58
|
+
var $regressiveTimer = document.querySelector('.regressive-timer'),
|
59
|
+
data_message = String($regressiveTimer.dataset.message),
|
60
|
+
data_seconds = Number($regressiveTimer.dataset.seconds),
|
38
61
|
current_time = new Date().getTime();
|
62
|
+
|
63
|
+
visibleTimer(
|
64
|
+
$regressiveTimer,
|
65
|
+
$regressiveTimer.dataset.visible
|
66
|
+
);
|
39
67
|
|
40
68
|
var time_expired = new Date();
|
41
69
|
time_expired.setSeconds(time_expired.getSeconds() + data_seconds);
|
@@ -45,23 +73,21 @@ AutomaticLogout.regressiveTimer = function(){;
|
|
45
73
|
|
46
74
|
if (data_seconds == 0) {
|
47
75
|
clearInterval(timerDecrement);
|
48
|
-
|
49
76
|
// limpa a sessão após o ok
|
50
|
-
|
51
|
-
AutomaticLogout.destroySession();
|
52
|
-
};
|
77
|
+
AutomaticLogout.destroySession(data_message);
|
53
78
|
}else{
|
54
79
|
//tempo descrecente
|
55
80
|
time_expired.setSeconds(time_expired.getSeconds() - 1);
|
56
81
|
|
57
|
-
var
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
82
|
+
var seconds_integer = (time_expired.getTime() - current_time) / 1000,
|
83
|
+
date_format = AutomaticLogout.parseDate(seconds_integer),
|
84
|
+
output_date_format = date_format.hours + ':' + date_format.minutes + ':' + date_format.seconds;
|
85
|
+
|
86
|
+
visibleTimer(
|
87
|
+
$regressiveTimer,
|
88
|
+
$regressiveTimer.dataset.visible,
|
89
|
+
output_date_format
|
90
|
+
);
|
65
91
|
}
|
66
92
|
|
67
93
|
data_seconds -= 1;
|
@@ -115,37 +141,4 @@ AutomaticLogout.parseDate = function(seconds_float){
|
|
115
141
|
minutes: minutes,
|
116
142
|
seconds: seconds
|
117
143
|
}
|
118
|
-
}
|
119
|
-
|
120
|
-
/**
|
121
|
-
* Method for request ajax, check value e logout
|
122
|
-
* @return {[type]} [description]
|
123
|
-
*/
|
124
|
-
AutomaticLogout.ajaxSessionTimeout = function(){
|
125
|
-
setTimeout(function () {
|
126
|
-
//TODO: Change to ES6/7 fetch() feature
|
127
|
-
$.ajax({
|
128
|
-
url: '/devise/automatic_logout/status',
|
129
|
-
success: function(data) {
|
130
|
-
if (data.seconds !== "null" && data.live === true){
|
131
|
-
|
132
|
-
var data_message = data.message, data_seconds = data.seconds;
|
133
|
-
|
134
|
-
if (data_seconds != 0 && data_seconds != ''){
|
135
|
-
var timerDecrement = setInterval(function(){
|
136
|
-
if (data_seconds == 0) {
|
137
|
-
clearInterval(timerDecrement);
|
138
|
-
// limpa a sessão após o ok do alertify
|
139
|
-
if (confirm(data_message)) {
|
140
|
-
AutomaticLogout.destroySession();
|
141
|
-
}
|
142
|
-
}
|
143
|
-
|
144
|
-
data_seconds -= 1;
|
145
|
-
}, 1000)
|
146
|
-
}
|
147
|
-
}
|
148
|
-
}
|
149
|
-
});
|
150
|
-
}, 1000); //1s
|
151
|
-
};
|
144
|
+
}
|
@@ -13,23 +13,23 @@ module Devise
|
|
13
13
|
# I18n.t devise.automaticlogout.message
|
14
14
|
c.session[:message] = I18n.t 'devise.automaticlogout.message' || 'Session expired!'
|
15
15
|
end
|
16
|
-
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
::ApplicationController.send :define_method, :automatic_logout_status do
|
18
|
+
Rails.logger.info 'Sessão atualizada'
|
19
|
+
render json: {
|
20
|
+
live: !current_user.nil?,
|
21
|
+
message: session[:message],
|
22
|
+
seconds: session[:seconds]
|
23
|
+
}, status: :ok
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
::ApplicationController.send :define_method, :automatic_logout_destroy do
|
27
|
+
Rails.logger.info 'Sessão destruída'
|
28
|
+
session[:seconds] = ''
|
29
|
+
session[:live] = !current_user.nil?
|
30
|
+
reset_session
|
31
|
+
redirect_to '/', notice: session[:message]
|
32
|
+
end
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
metadata
CHANGED
@@ -1,83 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-automaticlogout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thadeu Esteves Jr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-29 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
19
|
version: '4'
|
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
26
|
version: '4'
|
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
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: jquery-rails
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
38
|
+
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rubocop
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - "
|
45
|
+
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
47
|
version: '0'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - "
|
52
|
+
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: sqlite3
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - "
|
59
|
+
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
61
|
version: '0'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - "
|
66
|
+
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0'
|
83
69
|
description: Provides automatic session timeout in a Rails Devise application.
|
@@ -93,6 +79,10 @@ files:
|
|
93
79
|
- app/views/automatic_logout/_timer.html.erb
|
94
80
|
- config/routes.rb
|
95
81
|
- lib/assets/javascripts/automatic_logout.js
|
82
|
+
- lib/assets/javascripts/automatic_logout/classic.js
|
83
|
+
- lib/assets/javascripts/automatic_logout/jquery.js
|
84
|
+
- lib/assets/javascripts/automatic_logout/turbolinks-classic.js
|
85
|
+
- lib/assets/javascripts/automatic_logout/turbolinks.js
|
96
86
|
- lib/devise/automaticlogout.rb
|
97
87
|
- lib/devise/automaticlogout/controllers.rb
|
98
88
|
- lib/devise/automaticlogout/engine.rb
|