multi_session_store 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/bin/console +1 -1
- data/lib/multi_session_store.rb +23 -18
- data/lib/multi_session_store/default_url_options.rb +12 -0
- data/lib/multi_session_store/railtie.rb +15 -0
- data/lib/multi_session_store/subsession_generator_middleware.rb +34 -0
- data/lib/multi_session_store/version.rb +1 -1
- data/multi_session_store.gemspec +1 -1
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5da82bc7386c040cd586cc36c42feb917b41e55886c38b7dcdedd33705d478c
|
4
|
+
data.tar.gz: ea4d3ead909c521a46f2d61e1ad8a666508a65533652d70ce151e6c68a394cd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6fe4fd2eb79b0bdea61ac1e38b7956a46bf724b756bb2353d407c254f5a4376f97c6123287d1c95445c164547c471c25101e0ef92b5296e2d3307567855dd70
|
7
|
+
data.tar.gz: 226b38cfecfbb54d383aa2b7ea1460bab6a069d98361a16eb54860da8420b43ae550d84b20bb2b925442f21d75ab6bd0f693c26b62feb38fdfcce9e009ea752b
|
data/.gitignore
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
|
-
require "
|
4
|
+
require "multi_session_store"
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
data/lib/multi_session_store.rb
CHANGED
@@ -1,47 +1,52 @@
|
|
1
1
|
require "multi_session_store/version"
|
2
|
+
require "multi_session_store/subsession_generator_middleware"
|
3
|
+
require "multi_session_store/default_url_options"
|
4
|
+
require "multi_session_store/railtie" if defined? Rails
|
2
5
|
require "action_dispatch"
|
3
6
|
|
4
7
|
module ActionDispatch
|
5
8
|
module Session
|
6
9
|
class MultiSessionStore < AbstractStore
|
10
|
+
DEFAULT_SESSION_EXPIRATION = 24 * 60 * 60
|
11
|
+
|
7
12
|
def initialize(app, options = {})
|
8
|
-
|
9
|
-
options[:
|
10
|
-
@
|
13
|
+
options[:expire_after] ||= DEFAULT_SESSION_EXPIRATION
|
14
|
+
options[:param_name] ||= 'subsession_id'
|
15
|
+
@redis = options[:redis]
|
16
|
+
@param_name = options[:param_name]
|
11
17
|
@serializer = options[:serializer]
|
12
|
-
|
13
18
|
super
|
14
19
|
end
|
15
20
|
|
16
21
|
def find_session(env, sid)
|
17
|
-
sid
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
if sid
|
23
|
+
serialized_session_data = @redis.get session_store_key(env, sid)
|
24
|
+
session_data = serialized_session_data ? @serializer.parse(serialized_session_data) : {}
|
25
|
+
[sid, session_data]
|
26
|
+
else
|
27
|
+
[generate_sid, {}]
|
28
|
+
end
|
21
29
|
end
|
22
30
|
|
23
31
|
def write_session(env, sid, session, options)
|
24
|
-
key =
|
25
|
-
|
32
|
+
key = session_store_key env, sid
|
26
33
|
if session
|
27
|
-
@
|
34
|
+
@redis.set key, @serializer.dump(session), ex: options[:expire_after]
|
28
35
|
else
|
29
|
-
@
|
36
|
+
@redis.del key
|
30
37
|
end
|
31
|
-
|
32
38
|
sid
|
33
39
|
end
|
34
40
|
|
35
41
|
def delete_session(env, sid, options)
|
36
|
-
@
|
37
|
-
|
42
|
+
@redis.del session_store_key(env, sid)
|
38
43
|
sid
|
39
44
|
end
|
40
45
|
|
41
|
-
|
46
|
+
private
|
42
47
|
|
43
|
-
def
|
44
|
-
subsession_id = env.params[@
|
48
|
+
def session_store_key(env, sid)
|
49
|
+
subsession_id = env.params[@param_name] || 'no_subsession'
|
45
50
|
"_session_id:#{sid}:#{subsession_id}"
|
46
51
|
end
|
47
52
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MultiSessionStore
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
config.multi_session_store = ActiveSupport::OrderedOptions.new
|
4
|
+
|
5
|
+
initializer 'multi_session_store.add_middleware' do |app|
|
6
|
+
app.config.middleware.insert_before ActionDispatch::Session::MultiSessionStore,
|
7
|
+
MultiSessionStore::SubsessionGeneratorMiddleware,
|
8
|
+
exclude_paths: app.config.multi_session_store.exclude_paths
|
9
|
+
end
|
10
|
+
|
11
|
+
config.after_initialize do
|
12
|
+
ApplicationController.prepend MultiSessionStore::DefaultUrlOptions
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module MultiSessionStore
|
4
|
+
class SubsessionGeneratorMiddleware
|
5
|
+
def initialize(app, config = {})
|
6
|
+
@app = app
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
request = Rack::Request.new(env)
|
12
|
+
request.update_param 'subsession_id', new_subsession_id if subsession_id_is_needed?(request)
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def new_subsession_id
|
19
|
+
SecureRandom.hex
|
20
|
+
end
|
21
|
+
|
22
|
+
def subsession_id_is_needed?(request)
|
23
|
+
!request.params['subsession_id'] && !path_excluded?(request.path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def path_excluded?(current_path)
|
27
|
+
excluded_paths.any? { |excluded_path| excluded_path.match? current_path }
|
28
|
+
end
|
29
|
+
|
30
|
+
def excluded_paths
|
31
|
+
@config[:exclude_paths] ||= []
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/multi_session_store.gemspec
CHANGED
@@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 2.0"
|
32
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
-
spec.add_development_dependency "
|
34
|
+
spec.add_development_dependency "redis", "~> 4.0"
|
35
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_session_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emarsys Smart Insight developers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -67,19 +67,19 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: redis
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
75
|
+
version: '4.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
82
|
+
version: '4.0'
|
83
83
|
description: This gem provides a means to support multiple sessions across different
|
84
84
|
tabs in the same browser window.
|
85
85
|
email:
|
@@ -98,6 +98,9 @@ files:
|
|
98
98
|
- bin/console
|
99
99
|
- bin/setup
|
100
100
|
- lib/multi_session_store.rb
|
101
|
+
- lib/multi_session_store/default_url_options.rb
|
102
|
+
- lib/multi_session_store/railtie.rb
|
103
|
+
- lib/multi_session_store/subsession_generator_middleware.rb
|
101
104
|
- lib/multi_session_store/version.rb
|
102
105
|
- multi_session_store.gemspec
|
103
106
|
homepage: https://github.com/emartech/multi_session_store
|