session-check 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Session Check
2
2
 
3
- A gem that supplies a JS routine to check every 10 sec to see if your session has expired, and boots you to the sign in page if it is.
3
+ A gem that returns you to your application's sign in page when your Devise session expires.
4
4
 
5
5
  # Usage
6
6
 
@@ -18,4 +18,6 @@ You're done.
18
18
 
19
19
  A JS timeout checks a value supplied from your Devise config, and when it determines that the Devise session has expired,
20
20
  it takes the user to the sign in page. A global AJAX listener ensures AJAX heavy apps are catered for, by listening to each
21
- request and resetting the counter for you.
21
+ request and resetting the counter for you.
22
+
23
+ No server ping requests are made, so there is no extra load on your server.
@@ -0,0 +1,12 @@
1
+ class SessionChecksController < ActionController::Base
2
+
3
+ skip_authorization_check if defined?(CanCan)
4
+ session :off # Don't keep the session alive
5
+
6
+ # Find it there is a session, and if it has any warden information. If so, the user is logged in.
7
+ def time_to_session_expiry
8
+ sid = request.cookies['_session_id']
9
+ sess = Redis.current.get("www_session:#{sid}")
10
+ render json: {session_exists: (sess && sess.include?('warden'))}
11
+ end
12
+ end
@@ -3,24 +3,7 @@ require 'devise'
3
3
  module SessionCheckHelper
4
4
 
5
5
  def session_check
6
- "<script>
7
- (function(){
8
- var session_time_left = #{Devise.timeout_in};
9
- var session_check = function(){
10
- session_time_left = session_time_left - 10;
11
- if (session_time_left < 0){
12
- window.location = '/users/sign_in';
13
- }
14
- setTimeout(session_check, 10000);
15
- }
16
- setTimeout(session_check, 10000);
17
- $.ajaxSetup({
18
- complete: function(xhr) {
19
- session_time_left = #{Devise.timeout_in};
20
- }
21
- });
22
- }());
23
- </script>".html_safe
6
+ render :partial => '/session_check', locals: {session_time: Devise.timeout_in}
24
7
  end
25
8
 
26
9
  end
@@ -0,0 +1,28 @@
1
+ <script>
2
+ var should_session_check = <%= !current_user.nil? %>;
3
+ (function () {
4
+ var session_time_left = <%= session_time %>;
5
+ var force_sign_in = function () {
6
+ window.location = '/users/sign_in';
7
+ };
8
+ var session_check = function () {
9
+ session_time_left = session_time_left - 10;
10
+ if (should_session_check && session_time_left < 0) {
11
+ $.get('/session_check/time_to_session_expiry')
12
+ .done(function (d) {
13
+ if (!d.session_exists) {
14
+ force_sign_in();
15
+ }
16
+ })
17
+ .fail(force_sign_in);
18
+ }
19
+ setTimeout(session_check, 1000);
20
+ };
21
+ setTimeout(session_check, 1000);
22
+ $.ajaxSetup({
23
+ complete: function (xhr) {
24
+ session_time_left = <%= session_time %>;
25
+ }
26
+ });
27
+ }());
28
+ </script>
data/config/routes.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  Rails.application.routes.draw do
2
-
2
+ get 'session_check/time_to_session_expiry', to: 'session_checks#time_to_session_expiry'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  module Session
2
2
  module Check
3
- VERSION = '0.0.9'
3
+ VERSION = '0.1.0'
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.0.9
4
+ version: 0.1.0
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-02-19 00:00:00.000000000 Z
12
+ date: 2013-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  type: :runtime
@@ -27,6 +27,22 @@ 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'
30
46
  description:
31
47
  email:
32
48
  - harry@harrylascelles.com
@@ -34,6 +50,8 @@ executables: []
34
50
  extensions: []
35
51
  extra_rdoc_files: []
36
52
  files:
53
+ - app/controllers/session_checks_controller.rb
54
+ - app/views/_session_check.html.erb
37
55
  - app/helpers/session_check_helper.rb
38
56
  - lib/session/check/engine.rb
39
57
  - lib/session/check/version.rb