auto-session-timeout-kayleiburke 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c88753aa72041c3b2dbb48c68b4cc6b31fc0cde
4
+ data.tar.gz: e51f0203503466de83600b7d2e561ec7ffa39bda
5
+ SHA512:
6
+ metadata.gz: 68c0ae6519cbb4eb65ac6da81ef5361a694339ad603a7f4a8e8379e6ba4e713514efd58d48b65b4158713b60e9d29e7473f0b4c8d9b69cb5405f0ddf9c0c8328
7
+ data.tar.gz: e9d8384c1fb2e11047270d5829ce0c69b01228c7b2b93432d35ba5214cb0a7ad40a8e444f194a50793d2a8bb58a70263cfc8961951cb1f9aaa36550eff6a6c01
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ *.sublime-project
7
+ *.sublime-workspace
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
@@ -0,0 +1,5 @@
1
+ 2014-07-14 - Added jQuery support [krishnasrihari]
2
+
3
+ 2013-06-22 - Switched to Bundler for generating the gemspec [pelargir]
4
+
5
+ 2009-04-22 - Initial import [pelargir]
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in auto-session-timeout.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Matthew Bass (http://www.matthewbass.com)
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,111 @@
1
+ # auto-session-timeout
2
+
3
+ Provides automatic session timeout in a Rails application. Very easy
4
+ to install and configure. Have you ever wanted to force your users
5
+ off your app if they go idle for a certain period of time? Many
6
+ online banking sites use this technique. If your app is used on any
7
+ kind of public computer system, this plugin is a necessity.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'auto-session-timeout'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install auto-session-timeout
22
+
23
+ ## Usage
24
+
25
+ After installing, tell your application controller to use auto timeout:
26
+
27
+ class ApplicationController < ActionController::Base
28
+ auto_session_timeout 1.hour
29
+ ...
30
+ end
31
+
32
+ You will also need to insert this line inside the body tags in your
33
+ views. The easiest way to do this is to insert it once inside your
34
+ default or application-wide layout. Make sure you are only rendering
35
+ it if the user is logged in, otherwise the plugin will attempt to force
36
+ non-existent sessions to timeout, wreaking havoc:
37
+
38
+ <body>
39
+ <% if current_user %>
40
+ <%= auto_session_timeout_js %>
41
+ <% end %>
42
+ </body>
43
+
44
+ You need to setup two actions: one to return the session status and
45
+ another that runs when the session times out. You can use the default
46
+ actions included with the plugin by inserting this line in your target
47
+ controller (most likely your user or session controller):
48
+
49
+ class SessionsController < ApplicationController
50
+ auto_session_timeout_actions
51
+ end
52
+
53
+ To customize the default actions, simply override them. You can call
54
+ the render_session_status and render_session_timeout methods to use
55
+ the default implementation from the plugin, or you can define the
56
+ actions entirely with your own custom code:
57
+
58
+ class SessionsController < ApplicationController
59
+ def active
60
+ render_session_status
61
+ end
62
+
63
+ def timeout
64
+ render_session_timeout
65
+ end
66
+ end
67
+
68
+ In any of these cases, make sure to properly map the actions in
69
+ your routes.rb file:
70
+
71
+ match 'active' => 'sessions#active', via: :get
72
+ match 'timeout' => 'sessions#timeout', via: :get
73
+
74
+ You're done! Enjoy watching your sessions automatically timeout.
75
+
76
+ ## Additional Configuration
77
+
78
+ By default, the JavaScript code checks the server every 60 seconds for
79
+ active sessions. If you prefer that it check more frequently, pass a
80
+ frequency attribute to the helper method. The frequency is given in
81
+ seconds. The following example checks the server every 15 seconds:
82
+
83
+ <html>
84
+ <head>...</head>
85
+ <body>
86
+ <% if current_user %>
87
+ <%= auto_session_timeout_js frequency: 15 %>
88
+ <% end %>
89
+ ...
90
+ </body>
91
+ </html>
92
+
93
+ ## TODO
94
+
95
+ * current_user must be defined
96
+ * using Prototype vs. jQuery
97
+ * setting timeout in controller vs. user
98
+
99
+ ## Contributing
100
+
101
+ 1. Fork it
102
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
103
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
104
+ 4. Push to the branch (`git push origin my-new-feature`)
105
+ 5. Create new Pull Request
106
+
107
+ ## Resources
108
+
109
+ * Repository: http://github.com/pelargir/auto-session-timeout/
110
+ * Blog: http://www.matthewbass.com
111
+ * Author: Matthew Bass
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+ require 'bundler/gem_tasks'
5
+
6
+ task default: :test
7
+
8
+ Rake::TestTask.new('test') do |t|
9
+ t.pattern = 'test/*_test.rb'
10
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'auto/session/timeout/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "auto-session-timeout-kayleiburke"
8
+ spec.version = Auto::Session::Timeout::VERSION
9
+ spec.authors = ["Kaylei Burke"]
10
+ spec.email = ["kayleiburke@gmail.com"]
11
+ spec.description = %q{Provides automatic session timeout in a Rails application. Forked from http://github.com/pelargir/auto-session-timeout}
12
+ spec.summary = %q{Provides automatic session timeout in a Rails application. Forked from http://github.com/pelargir/auto-session-timeout}
13
+ spec.homepage = "http://github.com/kayleiburke/auto-session-timeout"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake", "~> 0"
23
+ spec.add_development_dependency "minitest", "~> 4.2"
24
+ spec.add_development_dependency "actionpack", "~> 3.2"
25
+ end
@@ -0,0 +1,2 @@
1
+ require 'auto_session_timeout'
2
+ require 'auto_session_timeout_helper'
@@ -0,0 +1,9 @@
1
+ require "auto/session/timeout/version"
2
+
3
+ module Auto
4
+ module Session
5
+ module Timeout
6
+ # Your code goes here...
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Auto
2
+ module Session
3
+ module Timeout
4
+ VERSION = "0.9.4"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ module AutoSessionTimeout
2
+
3
+ def self.included(controller)
4
+ controller.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def auto_session_timeout(seconds=nil, sign_in_path)
9
+ prepend_before_action do |c|
10
+ if c.session[:auto_session_expires_at] && c.session[:auto_session_expires_at] < Time.now && (sign_in_path ? !(c.env["PATH_INFO"] == sign_in_path && c.env["REQUEST_METHOD"] == "POST") : true)
11
+ c.send :reset_session
12
+ else
13
+ unless c.request.original_url.start_with?(c.send(:active_url))
14
+ offset = seconds || (current_user.respond_to?(:auto_timeout) ? current_user.auto_timeout : nil)
15
+ c.session[:auto_session_expires_at] = Time.now + offset if offset && offset > 0
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ def auto_session_timeout_actions
22
+ define_method(:active) { render_session_status }
23
+ define_method(:timeout) { render_session_timeout }
24
+ end
25
+ end
26
+
27
+ def render_session_status
28
+ response.headers["Etag"] = "" # clear etags to prevent caching
29
+ render plain: !!current_user, status: 200
30
+ end
31
+
32
+ def render_session_timeout
33
+ flash[:notice] = "Your session has timed out."
34
+ redirect_to "/login"
35
+ end
36
+
37
+ end
38
+
39
+ ActionController::Base.send :include, AutoSessionTimeout
@@ -0,0 +1,34 @@
1
+ module AutoSessionTimeoutHelper
2
+ def auto_session_timeout_js(options={})
3
+ frequency = options[:frequency] || 60
4
+ verbosity = options[:verbosity] || 2
5
+ 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')
26
+ window.location.href = '/timeout';
27
+ });
28
+ }
29
+ JS
30
+ javascript_tag(code)
31
+ end
32
+ end
33
+
34
+ ActionView::Base.send :include, AutoSessionTimeoutHelper
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ describe AutoSessionTimeoutHelper do
4
+
5
+ subject { Class.new(ActionView::Base).new }
6
+
7
+ describe "#auto_session_timeout_js" do
8
+ it "returns correct JS" do
9
+ assert_equal "<script type=\"text/javascript\">
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')
31
+ window.location.href = '/timeout';
32
+ });
33
+ }
34
+
35
+ //]]>
36
+ </script>", subject.auto_session_timeout_js
37
+ end
38
+
39
+ it "uses custom frequency when given" do
40
+ assert_match /frequency:120/, subject.auto_session_timeout_js(frequency: 120)
41
+ end
42
+
43
+ it "uses 60 when custom frequency is nil" do
44
+ assert_match /frequency:60/, subject.auto_session_timeout_js(frequency: nil)
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ describe AutoSessionTimeout do
4
+
5
+ it "tests something" do
6
+ assert true
7
+ end
8
+
9
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'minitest/autorun'
3
+ require 'action_controller'
4
+
5
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/auto-session-timeout')
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auto-session-timeout-kayleiburke
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.4
5
+ platform: ruby
6
+ authors:
7
+ - Kaylei Burke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: actionpack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ description: Provides automatic session timeout in a Rails application. Forked from
70
+ http://github.com/pelargir/auto-session-timeout
71
+ email:
72
+ - kayleiburke@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - CHANGELOG
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - auto-session-timeout.gemspec
84
+ - lib/auto-session-timeout.rb
85
+ - lib/auto/session/timeout.rb
86
+ - lib/auto/session/timeout/version.rb
87
+ - lib/auto_session_timeout.rb
88
+ - lib/auto_session_timeout_helper.rb
89
+ - test/auto_session_timeout_helper_test.rb
90
+ - test/auto_session_timeout_test.rb
91
+ - test/test_helper.rb
92
+ homepage: http://github.com/kayleiburke/auto-session-timeout
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.8
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Provides automatic session timeout in a Rails application. Forked from http://github.com/pelargir/auto-session-timeout
116
+ test_files:
117
+ - test/auto_session_timeout_helper_test.rb
118
+ - test/auto_session_timeout_test.rb
119
+ - test/test_helper.rb