rails-automaticlogout 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +77 -0
- data/Rakefile +2 -0
- data/app/assets/javascripts/automatic_logout.js +22 -0
- data/app/controllers/automatic_logout/sessions_controller.rb +26 -0
- data/app/views/automatic_logout/_timer.js.erb +60 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/routes.rb +4 -0
- data/lib/rails/automaticlogout/controllers/helpers.rb +25 -0
- data/lib/rails/automaticlogout/engine.rb +13 -0
- data/lib/rails/automaticlogout/version.rb +5 -0
- data/lib/rails/automaticlogout/views/helpers.rb +9 -0
- data/lib/rails-automaticlogout.rb +4 -0
- data/rails-automaticlogout.gemspec +24 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3746c6de9b1b0d8a3f5d5aa0ab9fd7f239a1aea3
|
4
|
+
data.tar.gz: e5159df8503aad1f9b4a44e93a60fc886b4d6206
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 086a52d6ba0b6f503aeb7926d943dcd90dbc363fc34669aeedb7026b42d4921678a6b1036fd5fde8e66e5ff59070ab20e97c4cd24ede4df5948a9feeab4c28de
|
7
|
+
data.tar.gz: b723d77f8d35cdfe778635572ee987e695606962bed92aa27de0e1c18b5e7ca6e5b3270ba276f7e8bd1a949562065ec0bfab202a9bf70fac3fc9f316634e7dce
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Rails Automatic Logout
|
2
|
+
By Thadeu Esteves Jr.
|
3
|
+
|
4
|
+
[](https://badge.fury.io/rb/rails-automaticlogout)
|
5
|
+
|
6
|
+
Provides automatic session timeout in a Rails application. Very easy to install and configure. Have you ever wanted to force your users off your app if they go idle for a certain period of time? Many online banking sites use this technique. If your app is used on any kind of public computer system, this plugin is a necessity.
|
7
|
+
|
8
|
+
* Force your users power off session
|
9
|
+
* show for they the regressive time
|
10
|
+
|
11
|
+
## Getting started
|
12
|
+
|
13
|
+
Rails Automatic Logout works only Rails 4. You can add it to your Gemfile with:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'rails-automaticlogout'
|
17
|
+
```
|
18
|
+
|
19
|
+
Then run bundle install
|
20
|
+
|
21
|
+
## How to use?
|
22
|
+
|
23
|
+
### Configure Controller
|
24
|
+
|
25
|
+
After installing, add in your application controller, _ex:_
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class ApplicationController < ActionController::Base
|
29
|
+
before_action :authenticate_user!
|
30
|
+
|
31
|
+
# by default is time 1.hour
|
32
|
+
automatic_logout_at
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
By default the time is _1.hour_
|
37
|
+
|
38
|
+
#### Change timeout value.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
class ApplicationController < ActionController::Base
|
42
|
+
before_action :authenticate_user!
|
43
|
+
|
44
|
+
# by default is time 1.hour
|
45
|
+
automatic_logout_at time: 5.minutes
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
#### Change message
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
class ApplicationController < ActionController::Base
|
53
|
+
before_action :authenticate_user!
|
54
|
+
|
55
|
+
# by default is time 1.hour
|
56
|
+
automatic_logout_at time: 12.hour,
|
57
|
+
message: 'Session expired! You will be redirect.'
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
### Configure View (OPTIONAL)
|
62
|
+
|
63
|
+
Use Helper in your view, for show regressive timer. Add this in your file application.html.erb
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
<%= regressive_timer %>
|
67
|
+
```
|
68
|
+
|
69
|
+
## TODO
|
70
|
+
* Add translations
|
71
|
+
* Add configurations for action_view
|
72
|
+
* Add Suport for Rails 5.x
|
73
|
+
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
We have a long list of valued contributors. Check them all at: https://github.com/Thadeu/rails-automaticlogout.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(function automaticLogoutJs(){
|
2
|
+
setTimeout(function () {
|
3
|
+
$.ajax({
|
4
|
+
url: '/status_automatic_logout',
|
5
|
+
success: function(data) {
|
6
|
+
if (data.timeout != "null" && data.live == true){
|
7
|
+
var response_timeout = (new Date(data.timeout).getTime());
|
8
|
+
|
9
|
+
setInterval(function(){
|
10
|
+
var now_time = (new Date().getTime());
|
11
|
+
|
12
|
+
if ((response_timeout < now_time) == true){
|
13
|
+
if (confirm(data.message)){
|
14
|
+
window.location.href = '/destroy_automatic_logout';
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}, data.seconds * 1000) // utiliza o mesmo valor em seconds que a pessoa irá ficar logado
|
18
|
+
}
|
19
|
+
}
|
20
|
+
});
|
21
|
+
}, 1000); //1s
|
22
|
+
}());
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module AutomaticLogout
|
2
|
+
class SessionsController < ApplicationController
|
3
|
+
skip_before_action :authenticate_user!, only: [:status, :destroy]
|
4
|
+
|
5
|
+
def status
|
6
|
+
response = {
|
7
|
+
live: !!current_user,
|
8
|
+
timeout: session[:auto_session_expires_at],
|
9
|
+
message: session[:message],
|
10
|
+
seconds: session[:seconds]
|
11
|
+
}
|
12
|
+
|
13
|
+
render json: response
|
14
|
+
end
|
15
|
+
|
16
|
+
def destroy
|
17
|
+
session[:auto_session_expires_at] = ''
|
18
|
+
session[:seconds] = ''
|
19
|
+
session[:live] = !!current_user
|
20
|
+
|
21
|
+
reset_session
|
22
|
+
|
23
|
+
redirect_to root_path, notice: session[:message]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
<script>
|
2
|
+
var timer = "<%= session[:auto_session_expires_at] %>";
|
3
|
+
var now_in_seconds = new Date().getTime() / 1000;
|
4
|
+
var timeout_in_seconds = new Date(timer).getTime() / 1000;
|
5
|
+
|
6
|
+
var target_date = new Date(timer).getTime();
|
7
|
+
var dias, horas, minutos, segundos;
|
8
|
+
|
9
|
+
var diff_in_seconds = new Number();
|
10
|
+
diff_in_seconds = (timeout_in_seconds - now_in_seconds).toFixed(0);
|
11
|
+
|
12
|
+
function regressive(){
|
13
|
+
|
14
|
+
if (diff_in_seconds <= 0){
|
15
|
+
if (confirm("<%= session[:message] %>")){
|
16
|
+
window.location.href = '/destroy_automatic_logout';
|
17
|
+
}
|
18
|
+
}else{
|
19
|
+
var current_date = new Date().getTime();
|
20
|
+
var segundos_f = (target_date - current_date) / 1000;
|
21
|
+
|
22
|
+
dias = parseInt(segundos_f / 86400);
|
23
|
+
segundos_f = segundos_f % 86400;
|
24
|
+
|
25
|
+
horas = parseInt(segundos_f / 3600);
|
26
|
+
segundos_f = segundos_f % 3600;
|
27
|
+
|
28
|
+
minutos = parseInt(segundos_f / 60);
|
29
|
+
segundos = parseInt(segundos_f % 60);
|
30
|
+
|
31
|
+
// Formata o número menor que dez, ex: 08, 07, ...
|
32
|
+
if(horas < 10){
|
33
|
+
horas = "0"+horas;
|
34
|
+
horas = horas.substr(0, 2);
|
35
|
+
}
|
36
|
+
|
37
|
+
if(minutos < 10){
|
38
|
+
minutos = "0"+minutos;
|
39
|
+
minutos = minutos.substr(0, 2);
|
40
|
+
}
|
41
|
+
|
42
|
+
if(segundos <=9){
|
43
|
+
segundos = "0"+segundos;
|
44
|
+
}
|
45
|
+
|
46
|
+
if (diff_in_seconds >= 0){
|
47
|
+
$('.regressive-timer').text(horas + ':' + minutos + ':' + segundos);
|
48
|
+
}
|
49
|
+
|
50
|
+
setTimeout('regressive()',1000);
|
51
|
+
|
52
|
+
diff_in_seconds--;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
regressive();
|
57
|
+
|
58
|
+
</script>
|
59
|
+
|
60
|
+
<div class="regressive-timer"></div>
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "automaticlogout"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/config/routes.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Rails::AutomaticLogout
|
2
|
+
module Controllers
|
3
|
+
module Helpers
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def automatic_logout_at(time: 1.hour, message: "Session expired! You will be redirect.")
|
10
|
+
prepend_before_filter do |c|
|
11
|
+
if c.session[:auto_session_expires_at].present? && c.session[:auto_session_expires_at] < Time.now
|
12
|
+
c.send :reset_session
|
13
|
+
else
|
14
|
+
if current_user
|
15
|
+
c.session[:auto_session_expires_at] = Time.now + time
|
16
|
+
c.session[:message] = message
|
17
|
+
c.session[:seconds] = time.seconds
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Rails
|
2
|
+
module AutomaticLogout
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
ActiveSupport.on_load :action_controller do
|
5
|
+
include Rails::AutomaticLogout::Controllers::Helpers if defined?(Rails::AutomaticLogout::Controllers::Helpers)
|
6
|
+
end
|
7
|
+
|
8
|
+
ActiveSupport.on_load :action_view do
|
9
|
+
include Rails::AutomaticLogout::Views::Helpers if defined?(Rails::AutomaticLogout::Views::Helpers)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails/automaticlogout/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails-automaticlogout"
|
8
|
+
spec.version = Rails::AutomaticLogout::VERSION
|
9
|
+
spec.authors = ["Thadeu Esteves Jr"]
|
10
|
+
spec.email = ["tadeuu@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provides automatic session timeout in a Rails application.}
|
13
|
+
spec.description = %q{Provides automatic session timeout in a Rails application.}
|
14
|
+
spec.homepage = "http://github.com/thadeu/rails-automaticlogout"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "actionpack", "~> 3.2"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-automaticlogout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thadeu Esteves Jr
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-09 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: actionpack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
description: Provides automatic session timeout in a Rails application.
|
56
|
+
email:
|
57
|
+
- tadeuu@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- app/assets/javascripts/automatic_logout.js
|
67
|
+
- app/controllers/automatic_logout/sessions_controller.rb
|
68
|
+
- app/views/automatic_logout/_timer.js.erb
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- config/routes.rb
|
72
|
+
- lib/rails-automaticlogout.rb
|
73
|
+
- lib/rails/automaticlogout/controllers/helpers.rb
|
74
|
+
- lib/rails/automaticlogout/engine.rb
|
75
|
+
- lib/rails/automaticlogout/version.rb
|
76
|
+
- lib/rails/automaticlogout/views/helpers.rb
|
77
|
+
- rails-automaticlogout.gemspec
|
78
|
+
homepage: http://github.com/thadeu/rails-automaticlogout
|
79
|
+
licenses: []
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.6.8
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Provides automatic session timeout in a Rails application.
|
101
|
+
test_files: []
|