rails-automaticlogout 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 886bac714ec7c95fef68f92b348d4efaa3c6a81c
4
- data.tar.gz: 926892faf3a86b51ee29e46f98065019b4e9fd96
3
+ metadata.gz: 0c8e1435e67f34868aa59b47da980d0314ed0b39
4
+ data.tar.gz: 49647ce23fdbc6c37a488061ccc0b2fe7fcadcef
5
5
  SHA512:
6
- metadata.gz: 5132ad23ef7b9f2836765ff32c2eed36abdff1bcd1c9be911a1c8c1e0b1291ccd7b9acd0effa5179c45efb762609bcd442fc1e6d112d8e190a83c0fc2c851776
7
- data.tar.gz: 96a56ccee0dd739254710d14f79d539bf2641c6a42274a6d07b24796dad01b082616803f67fdc48303b0fd3b2696b9faf92208ff0e8f0307ece53c5fa7ef19b6
6
+ metadata.gz: 92a73343a68b45a2384cf0fa95210ffcc89e3acaefc33221e870ba5127e25c13b876e9b7f806a37c01ccdf84074a9689c1a43dad83dcc31f634125dc42a72350
7
+ data.tar.gz: 72886b67e1a151ffaa4d58e06314ee62f0e1e83256fcb5f4fe87d60eae64e58095a07604346e5cde8b4919ba1a985c022a8b0f89d2bd3fdec660b37ebfcfbe54
@@ -32,8 +32,7 @@ AutomaticLogout.regressiveTimer = function(){;
32
32
  * @param {[type]} '.regressive-timer' [description]
33
33
  * @return {[type]} [description]
34
34
  */
35
- var data_timer = $('.regressive-timer').data('expires-at'),
36
- data_message = $('.regressive-timer').data('message'),
35
+ var data_message = $('.regressive-timer').data('message'),
37
36
  data_seconds = $('.regressive-timer').data('seconds'),
38
37
  current_time = new Date().getTime();
39
38
 
@@ -124,18 +123,21 @@ AutomaticLogout.ajaxSessionTimeout = function(){
124
123
  $.ajax({
125
124
  url: '/status_automatic_logout',
126
125
  success: function(data) {
127
- if (data.timeout !== "null" && data.live === true){
128
- var response_timeout = (new Date(data.timeout).getTime());
129
-
130
- setInterval(function(){
131
- var now_time = (new Date().getTime());
132
-
133
- if ((response_timeout < now_time) === true){
126
+ if (data.seconds !== "null" && data.live === true){
127
+
128
+ var data_message = data.message, data_seconds = data.seconds;
129
+
130
+ var timerDecrement = setInterval(function(){
131
+ if (data_seconds == 0) {
132
+ clearInterval(timerDecrement);
133
+ // limpa a sessão após o ok do alertify
134
134
  alertify.alert(data_message, function () {
135
- window.location.href = '/destroy_automatic_logout';
135
+ AutomaticLogout.destroySession();
136
136
  });
137
137
  }
138
- }, (data.seconds / 2) * 1000) // utiliza o mesmo valor em seconds que a pessoa irá ficar logado
138
+
139
+ data_seconds -= 1;
140
+ }, 1000)
139
141
  }
140
142
  }
141
143
  });
@@ -1,5 +1,4 @@
1
1
  <div class="regressive-timer"
2
- data-expires-at="<%= session[:auto_session_expires_at] %>"
3
2
  data-seconds="<%= session[:seconds] %>"
4
3
  data-message="<%= session[:message] %>">
5
4
  </div>
@@ -15,21 +15,17 @@ module Rails::AutomaticLogout
15
15
  end
16
16
 
17
17
  def expires_at_in_seconds(time)
18
- # ((current_time + time)).strftime("%s").to_i
19
18
  time.seconds.to_i
20
19
  end
21
20
 
22
21
  module ClassMethods
23
22
  def automatic_logout_at(time: 1.hour, message: "Session expired! You will be redirect.")
24
23
  prepend_before_filter do |c|
25
- if c.session[:auto_session_expires_at].present? && c.session[:auto_session_expires_at] < current_time
26
- c.send :reset_session
24
+ if current_user
25
+ c.session[:seconds] = expires_at_in_seconds(time)
26
+ c.session[:message] = message
27
27
  else
28
- if current_user
29
- c.session[:auto_session_expires_at] = expires_at(time)
30
- c.session[:seconds] = expires_at_in_seconds(time)
31
- c.session[:message] = message
32
- end
28
+ c.send :reset_session
33
29
  end
34
30
  end
35
31
  end
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module AutomaticLogout
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-automaticlogout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thadeu Esteves Jr