rails-automaticlogout 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +2 -1
- data/app/assets/javascripts/automatic_logout.js +124 -5
- data/app/views/automatic_logout/_timer.html.erb +4 -0
- data/lib/rails/automaticlogout/version.rb +1 -1
- data/lib/rails/automaticlogout/views/helpers.rb +1 -1
- metadata +3 -3
- data/app/views/automatic_logout/_timer.js.erb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 755f81a5ef6277ff52d72f91f1d4f4fcf1c2ba68
|
4
|
+
data.tar.gz: c93b1eeefd9e9570a012ea8cc7dcad8c100281b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b2c5813145e6843f857059277ee27567fca9e86a3bb3ef33478f8710a180069e9a64adda6361f5fe751ba2de68703d71f25f1b0d3ff9725aeeeafbdd401657f
|
7
|
+
data.tar.gz: 2a313869e0f8bb3c453077371fe6a5b852d6872003585ffe7c5c539f1a88fc90cd98fc958eda442a21c009c32b6e957a79a71dbbe28f254b765563ed256379b5
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Rails Automatic Logout
|
2
2
|
By Thadeu Esteves Jr.
|
3
3
|
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/rails-automaticlogout.
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/rails-automaticlogout.png)](https://badge.fury.io/rb/rails-automaticlogout)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/Thadeu/rails-automaticlogout/badges/gpa.svg)](https://codeclimate.com/github/Thadeu/rails-automaticlogout)
|
5
6
|
|
6
7
|
Provides automatic session timeout in a Rails application. Very easy to install and configure. Have you ever wanted to force your users off your app if they go idle for a certain period of time? Many online banking sites use this technique. If your app is used on any kind of public computer system, this plugin is a necessity.
|
7
8
|
|
@@ -1,22 +1,141 @@
|
|
1
|
-
|
1
|
+
/**
|
2
|
+
* Module AutomaticLogout for JS Files
|
3
|
+
* @type {[type]}
|
4
|
+
*/
|
5
|
+
var AutomaticLogout = AutomaticLogout || {};
|
6
|
+
|
7
|
+
$(document).ready(function(){
|
8
|
+
var $regressiveTimer = $('.regressive-timer');
|
9
|
+
|
10
|
+
($regressiveTimer.length > 0 &&
|
11
|
+
$regressiveTimer.data('expires-at') !== '')
|
12
|
+
? AutomaticLogout.regressiveTimer()
|
13
|
+
: AutomaticLogout.ajaxSessionTimeout();
|
14
|
+
});
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Send request for destroy session current_user
|
18
|
+
* @return {[type]} [description]
|
19
|
+
*/
|
20
|
+
AutomaticLogout.destroySession = function(){
|
21
|
+
return window.location.href = '/destroy_automatic_logout';
|
22
|
+
}
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Method regressive time based in session auto expired at
|
26
|
+
* @param {[type]} date_session [description]
|
27
|
+
* @return {[type]} [description]
|
28
|
+
*/
|
29
|
+
AutomaticLogout.regressiveTimer = function(){;
|
30
|
+
/**
|
31
|
+
* Variables used
|
32
|
+
* @param {[type]} '.regressive-timer' [description]
|
33
|
+
* @return {[type]} [description]
|
34
|
+
*/
|
35
|
+
var data_timer = $('.regressive-timer').data('expires-at'),
|
36
|
+
data_message = $('.regressive-timer').data('message'),
|
37
|
+
now_in_seconds = new Date().getTime() / 1000,
|
38
|
+
timeout_in_seconds = new Date(data_timer).getTime() / 1000,
|
39
|
+
diff_in_seconds = new Number(),
|
40
|
+
target_date = new Date(data_timer).getTime(),
|
41
|
+
current_date = new Date().getTime();
|
42
|
+
|
43
|
+
/**
|
44
|
+
* diff in seconds with 0 decimals
|
45
|
+
* @param {[type]} timeout_in_seconds - now_in_seconds [description]
|
46
|
+
* @return {[type]} [description]
|
47
|
+
*/
|
48
|
+
diff_in_seconds = (timeout_in_seconds - now_in_seconds).toFixed(0);
|
49
|
+
|
50
|
+
if (diff_in_seconds <= 0){
|
51
|
+
if (confirm(data_message)){
|
52
|
+
AutomaticLogout.destroySession();
|
53
|
+
}
|
54
|
+
}else{
|
55
|
+
var seconds_float = (target_date - current_date) / 1000,
|
56
|
+
date_format = AutomaticLogout.parseDate(seconds_float);
|
57
|
+
|
58
|
+
if (diff_in_seconds >= 0){
|
59
|
+
$('.regressive-timer').text(date_format.hours + ':' + date_format.minutes + ':' + date_format.seconds);
|
60
|
+
}
|
61
|
+
|
62
|
+
setTimeout('AutomaticLogout.regressiveTimer()',1000);
|
63
|
+
|
64
|
+
diff_in_seconds--;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Parse Date
|
70
|
+
* @param float seconds seconds_float [description]
|
71
|
+
* @return {
|
72
|
+
* days: days,
|
73
|
+
* hours: hours,
|
74
|
+
* minutes: minutes,
|
75
|
+
* seconds: seconds
|
76
|
+
* }
|
77
|
+
*/
|
78
|
+
AutomaticLogout.parseDate = function(seconds_float){
|
79
|
+
|
80
|
+
var days,
|
81
|
+
hours,
|
82
|
+
minutes,
|
83
|
+
seconds;
|
84
|
+
|
85
|
+
days = parseInt(seconds_float / 86400);
|
86
|
+
seconds_float = seconds_float % 86400;
|
87
|
+
|
88
|
+
hours = parseInt(seconds_float / 3600);
|
89
|
+
seconds_float = seconds_float % 3600;
|
90
|
+
|
91
|
+
minutes = parseInt(seconds_float / 60);
|
92
|
+
seconds = parseInt(seconds_float % 60);
|
93
|
+
|
94
|
+
if(hours < 10){
|
95
|
+
hours = "0"+hours;
|
96
|
+
hours = hours.substr(0, 2);
|
97
|
+
}
|
98
|
+
|
99
|
+
if(minutes < 10){
|
100
|
+
minutes = "0"+minutes;
|
101
|
+
minutes = minutes.substr(0, 2);
|
102
|
+
}
|
103
|
+
|
104
|
+
if(seconds <=9){
|
105
|
+
seconds = "0"+seconds;
|
106
|
+
}
|
107
|
+
|
108
|
+
return {
|
109
|
+
days: days,
|
110
|
+
hours: hours,
|
111
|
+
minutes: minutes,
|
112
|
+
seconds: seconds
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Method for request ajax, check value e logout
|
118
|
+
* @return {[type]} [description]
|
119
|
+
*/
|
120
|
+
AutomaticLogout.ajaxSessionTimeout = function(){
|
2
121
|
setTimeout(function () {
|
3
122
|
$.ajax({
|
4
123
|
url: '/status_automatic_logout',
|
5
124
|
success: function(data) {
|
6
|
-
if (data.timeout
|
125
|
+
if (data.timeout !== "null" && data.live === true){
|
7
126
|
var response_timeout = (new Date(data.timeout).getTime());
|
8
127
|
|
9
128
|
setInterval(function(){
|
10
129
|
var now_time = (new Date().getTime());
|
11
130
|
|
12
|
-
if ((response_timeout < now_time)
|
131
|
+
if ((response_timeout < now_time) === true){
|
13
132
|
if (confirm(data.message)){
|
14
133
|
window.location.href = '/destroy_automatic_logout';
|
15
134
|
}
|
16
135
|
}
|
17
|
-
}, data.seconds * 1000) // utiliza o mesmo valor em seconds que a pessoa irá ficar logado
|
136
|
+
}, (data.seconds / 2) * 1000) // utiliza o mesmo valor em seconds que a pessoa irá ficar logado
|
18
137
|
}
|
19
138
|
}
|
20
139
|
});
|
21
140
|
}, 1000); //1s
|
22
|
-
}
|
141
|
+
};
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-automaticlogout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thadeu Esteves Jr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,7 +65,7 @@ files:
|
|
65
65
|
- Rakefile
|
66
66
|
- app/assets/javascripts/automatic_logout.js
|
67
67
|
- app/controllers/automatic_logout/sessions_controller.rb
|
68
|
-
- app/views/automatic_logout/_timer.
|
68
|
+
- app/views/automatic_logout/_timer.html.erb
|
69
69
|
- bin/console
|
70
70
|
- bin/setup
|
71
71
|
- config/routes.rb
|
@@ -1,60 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
var timer = "<%= session[:auto_session_expires_at] %>";
|
3
|
-
var now_in_seconds = new Date().getTime() / 1000;
|
4
|
-
var timeout_in_seconds = new Date(timer).getTime() / 1000;
|
5
|
-
|
6
|
-
var target_date = new Date(timer).getTime();
|
7
|
-
var dias, horas, minutos, segundos;
|
8
|
-
|
9
|
-
var diff_in_seconds = new Number();
|
10
|
-
diff_in_seconds = (timeout_in_seconds - now_in_seconds).toFixed(0);
|
11
|
-
|
12
|
-
function regressive(){
|
13
|
-
|
14
|
-
if (diff_in_seconds <= 0){
|
15
|
-
if (confirm("<%= session[:message] %>")){
|
16
|
-
window.location.href = '/destroy_automatic_logout';
|
17
|
-
}
|
18
|
-
}else{
|
19
|
-
var current_date = new Date().getTime();
|
20
|
-
var segundos_f = (target_date - current_date) / 1000;
|
21
|
-
|
22
|
-
dias = parseInt(segundos_f / 86400);
|
23
|
-
segundos_f = segundos_f % 86400;
|
24
|
-
|
25
|
-
horas = parseInt(segundos_f / 3600);
|
26
|
-
segundos_f = segundos_f % 3600;
|
27
|
-
|
28
|
-
minutos = parseInt(segundos_f / 60);
|
29
|
-
segundos = parseInt(segundos_f % 60);
|
30
|
-
|
31
|
-
// Formata o número menor que dez, ex: 08, 07, ...
|
32
|
-
if(horas < 10){
|
33
|
-
horas = "0"+horas;
|
34
|
-
horas = horas.substr(0, 2);
|
35
|
-
}
|
36
|
-
|
37
|
-
if(minutos < 10){
|
38
|
-
minutos = "0"+minutos;
|
39
|
-
minutos = minutos.substr(0, 2);
|
40
|
-
}
|
41
|
-
|
42
|
-
if(segundos <=9){
|
43
|
-
segundos = "0"+segundos;
|
44
|
-
}
|
45
|
-
|
46
|
-
if (diff_in_seconds >= 0){
|
47
|
-
$('.regressive-timer').text(horas + ':' + minutos + ':' + segundos);
|
48
|
-
}
|
49
|
-
|
50
|
-
setTimeout('regressive()',1000);
|
51
|
-
|
52
|
-
diff_in_seconds--;
|
53
|
-
}
|
54
|
-
}
|
55
|
-
|
56
|
-
regressive();
|
57
|
-
|
58
|
-
</script>
|
59
|
-
|
60
|
-
<div class="regressive-timer"></div>
|