session-check 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,12 +3,23 @@ require 'session_off'
3
3
  class SessionChecksController < ActionController::Base
4
4
 
5
5
  skip_authorization_check if defined?(CanCan)
6
- session :off # Don't keep the session alive
6
+
7
+ prepend_before_filter :dont_update_request_time
7
8
 
8
9
  # Find it there is a session, and if it has any warden information. If so, the user is logged in.
9
10
  def time_to_session_expiry
10
- sid = request.cookies['_session_id']
11
- sess = Redis.current.get("#{REDIS_SESSION_NAMESPACE}:#{sid}")
12
- render json: {session_exists: (sess && sess.include?('warden'))}
11
+ session_exists = false
12
+ session_expires_in = 0
13
+ if current_user
14
+ session_exists = true
15
+ # This calculates how many seconds there are until they are logged out
16
+ session_expires_in = User.timeout_in - Time.now.utc.to_i + session['warden.user.user.session']['last_request_at'].to_i rescue 1000000
17
+ end
18
+ render json: {session_exists: session_exists, session_expires_in: session_expires_in}
19
+ end
20
+
21
+ # This ensures this requeust ping doesn't update their last access time.
22
+ def dont_update_request_time
23
+ env['devise.skip_trackable'] = true
13
24
  end
14
25
  end
@@ -13,13 +13,15 @@
13
13
  .done(function (d) {
14
14
  if (!d.session_exists) {
15
15
  force_sign_in();
16
+ } else {
17
+ session_time_left = d.session_expires_in;
16
18
  }
17
19
  })
18
20
  .fail(force_sign_in);
19
21
  }
20
- setTimeout(session_check, check_every_s * 1000);
22
+ setTimeout(session_check, check_every_s * 5000);
21
23
  };
22
- setTimeout(session_check, check_every_s * 1000);
24
+ setTimeout(session_check, check_every_s * 5000);
23
25
  <% if reset_counter_on_ajax %>
24
26
  $.ajaxSetup({
25
27
  complete: function (xhr) {
@@ -1,5 +1,5 @@
1
1
  module Session
2
2
  module Check
3
- VERSION = '0.1.6'
3
+ VERSION = '0.1.7'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: session-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-01 00:00:00.000000000 Z
12
+ date: 2013-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  type: :runtime
@@ -27,22 +27,6 @@ dependencies:
27
27
  - - ! '>'
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.0'
30
- - !ruby/object:Gem::Dependency
31
- type: :runtime
32
- name: session_off
33
- prerelease: false
34
- requirement: !ruby/object:Gem::Requirement
35
- none: false
36
- requirements:
37
- - - ! '>='
38
- - !ruby/object:Gem::Version
39
- version: '0'
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
30
  description:
47
31
  email:
48
32
  - harry@harrylascelles.com