auto-session-timeout 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77ae45c61583c38e509d9db9197d0b20043fc183
4
- data.tar.gz: 0173b194b2ae4b8b1c4dabdb957cf78256cf83da
3
+ metadata.gz: 3561cc313c2dc97c96fb2a2a5931c01c8a442706
4
+ data.tar.gz: d5c805a2efeb3af57dad7d2b23aa4aa55b1df902
5
5
  SHA512:
6
- metadata.gz: 9d70255cc2a19147c9e48cde559c828a396c8936001bb4054703ec42fa837c2e7932d437964bffdcd5edaa1c8934f55694c8ba373a5bdacb4a466870037117b4
7
- data.tar.gz: cb1b5c13b32213881d94bd7cc329afa6cde3bc13ad0dbd4b25699cd81d52e8fb406dc14172d48131abf4f20510a7545960b56643a56fde6b29d2666f96fd1105
6
+ metadata.gz: 3dff428123f23f12a7cd5f9cba6a25a8d8576db3519ab01c1a70586e6ec84cf52377910207339adcc4a0360106bdd69b35dcb8bad73f68b452d005223ac0452f
7
+ data.tar.gz: 022ed3b160ee413a4e703bd097acdec9b865994c2d42cf57276b1087591e220f2859b69edae1c293815741ea6daa01b4bc69a4c11fdf920dba5e9ad76cbb8ba0
@@ -1,7 +1,7 @@
1
1
  module Auto
2
2
  module Session
3
3
  module Timeout
4
- VERSION = "0.9.4"
4
+ VERSION = "0.9.5"
5
5
  end
6
6
  end
7
7
  end
@@ -6,6 +6,7 @@ module AutoSessionTimeout
6
6
 
7
7
  module ClassMethods
8
8
  def auto_session_timeout(seconds=nil)
9
+ protect_from_forgery except: [:active, :timeout]
9
10
  prepend_before_action do |c|
10
11
  if c.session[:auto_session_expires_at] && c.session[:auto_session_expires_at] < Time.now
11
12
  c.send :reset_session
@@ -2,33 +2,26 @@ module AutoSessionTimeoutHelper
2
2
  def auto_session_timeout_js(options={})
3
3
  frequency = options[:frequency] || 60
4
4
  verbosity = options[:verbosity] || 2
5
+ attributes = options[:attributes] || {}
5
6
  code = <<JS
6
- if (typeof(Ajax) != 'undefined') {
7
- new Ajax.PeriodicalUpdater('', '/active', {frequency:#{frequency}, method:'get', onSuccess: function(e) {
8
- if (e.responseText == 'false') window.location.href = '/timeout';
9
- }});
10
- }else if(typeof(jQuery) != 'undefined'){
11
- function PeriodicalQuery() {
12
- $.ajax({
13
- url: '/active',
14
- success: function(data) {
15
- if(data == 'false'){
16
- window.location.href = '/timeout';
17
- }
18
- }
19
- });
20
- setTimeout(PeriodicalQuery, (#{frequency} * 1000));
21
- }
22
- setTimeout(PeriodicalQuery, (#{frequency} * 1000));
23
- } else {
24
- $.PeriodicalUpdater('/active', {minTimeout:#{frequency * 1000}, multiplier:0, method:'get', verbose:#{verbosity}}, function(remoteData, success) {
25
- if (success == 'success' && remoteData == 'false')
7
+ function PeriodicalQuery() {
8
+ var request = new XMLHttpRequest();
9
+ request.onload = function (event) {
10
+ var status = event.target.status;
11
+ var response = event.target.response;
12
+ if (status === 200 && (response === false || response === 'false')) {
26
13
  window.location.href = '/timeout';
27
- });
14
+ }
15
+ };
16
+ request.open('GET', '/active', true);
17
+ request.responseType = 'json';
18
+ request.send();
19
+ setTimeout(PeriodicalQuery, (#{frequency} * 1000));
28
20
  }
21
+ setTimeout(PeriodicalQuery, (#{frequency} * 1000));
29
22
  JS
30
- javascript_tag(code)
23
+ javascript_tag(code, attributes)
31
24
  end
32
25
  end
33
26
 
34
- ActionView::Base.send :include, AutoSessionTimeoutHelper
27
+ ActionView::Base.send :include, AutoSessionTimeoutHelper
@@ -8,40 +8,36 @@ describe AutoSessionTimeoutHelper do
8
8
  it "returns correct JS" do
9
9
  assert_equal "<script type=\"text/javascript\">
10
10
  //<![CDATA[
11
- if (typeof(Ajax) != 'undefined') {
12
- new Ajax.PeriodicalUpdater('', '/active', {frequency:60, method:'get', onSuccess: function(e) {
13
- if (e.responseText == 'false') window.location.href = '/timeout';
14
- }});
15
- }else if(typeof(jQuery) != 'undefined'){
16
- function PeriodicalQuery() {
17
- $.ajax({
18
- url: '/active',
19
- success: function(data) {
20
- if(data == 'false'){
21
- window.location.href = '/timeout';
22
- }
23
- }
24
- });
25
- setTimeout(PeriodicalQuery, (60 * 1000));
26
- }
27
- setTimeout(PeriodicalQuery, (60 * 1000));
28
- } else {
29
- $.PeriodicalUpdater('/active', {minTimeout:60000, multiplier:0, method:'get', verbose:2}, function(remoteData, success) {
30
- if (success == 'success' && remoteData == 'false')
11
+ function PeriodicalQuery() {
12
+ var request = new XMLHttpRequest();
13
+ request.onload = function (event) {
14
+ var status = event.target.status;
15
+ var response = event.target.response;
16
+ if (status === 200 && (response === false || response === 'false')) {
31
17
  window.location.href = '/timeout';
32
- });
18
+ }
19
+ };
20
+ request.open('GET', '/active', true);
21
+ request.responseType = 'json';
22
+ request.send();
23
+ setTimeout(PeriodicalQuery, (60 * 1000));
33
24
  }
25
+ setTimeout(PeriodicalQuery, (60 * 1000));
34
26
 
35
27
  //]]>
36
28
  </script>", subject.auto_session_timeout_js
37
29
  end
38
30
 
39
31
  it "uses custom frequency when given" do
40
- assert_match /frequency:120/, subject.auto_session_timeout_js(frequency: 120)
32
+ assert_match /120/, subject.auto_session_timeout_js(frequency: 120)
41
33
  end
42
34
 
43
35
  it "uses 60 when custom frequency is nil" do
44
- assert_match /frequency:60/, subject.auto_session_timeout_js(frequency: nil)
36
+ assert_match /60/, subject.auto_session_timeout_js(frequency: nil)
37
+ end
38
+
39
+ it "accepts attributes" do
40
+ assert_match /data-turbolinks-eval="false"/, subject.auto_session_timeout_js(attributes: { 'data-turbolinks-eval': 'false' })
45
41
  end
46
42
  end
47
43
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto-session-timeout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Bass
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-16 00:00:00.000000000 Z
11
+ date: 2017-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler