has_global_session 0.8.6 → 0.8.7
Sign up to get free protection for your applications and to get access to all the features.
data/has_global_session.gemspec
CHANGED
@@ -7,8 +7,8 @@ spec = Gem::Specification.new do |s|
|
|
7
7
|
s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
|
8
8
|
|
9
9
|
s.name = 'has_global_session'
|
10
|
-
s.version = '0.8.
|
11
|
-
s.date = '2010-06-
|
10
|
+
s.version = '0.8.7'
|
11
|
+
s.date = '2010-06-28'
|
12
12
|
|
13
13
|
s.authors = ['Tony Spataro']
|
14
14
|
s.email = 'code@tracker.xeger.net'
|
@@ -1,8 +1,25 @@
|
|
1
1
|
module HasGlobalSession
|
2
2
|
module ActionControllerInstanceMethods
|
3
|
+
def self.included(base)
|
4
|
+
if Configuration['integrated']
|
5
|
+
base.alias_method_chain :session, :global_session
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
def global_session
|
4
|
-
|
10
|
+
@global_session
|
11
|
+
end
|
12
|
+
|
13
|
+
def session_with_global_session
|
14
|
+
if global_session
|
15
|
+
@integrated_session ||= IntegratedSession.new(session_without_global_session, global_session)
|
16
|
+
return @integrated_session
|
17
|
+
else
|
18
|
+
return session_without_global_session
|
19
|
+
end
|
20
|
+
end
|
5
21
|
|
22
|
+
def global_session_read_cookie
|
6
23
|
if (klass = Configuration['directory'])
|
7
24
|
klass = klass.constantize
|
8
25
|
else
|
@@ -10,49 +27,45 @@ module HasGlobalSession
|
|
10
27
|
end
|
11
28
|
|
12
29
|
directory = klass.new(File.join(RAILS_ROOT, 'config', 'authorities'))
|
13
|
-
cookie_name = Configuration['cookie']['name']
|
30
|
+
cookie_name = Configuration['cookie']['name']
|
14
31
|
cookie = cookies[cookie_name]
|
15
32
|
|
16
33
|
begin
|
17
34
|
#unserialize the global session from the cookie, or
|
18
35
|
#initialize a new global session if cookie == nil
|
19
36
|
@global_session = GlobalSession.new(directory, cookie)
|
37
|
+
return true
|
20
38
|
rescue Exception => e
|
21
|
-
#silently recover from any error by initializing a new global session
|
22
|
-
#the new session will be unauthenticated.
|
23
|
-
directory.report_exception(e, cookie)
|
39
|
+
#silently recover from any error by initializing a new global session
|
24
40
|
@global_session = GlobalSession.new(directory)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
if Configuration['integrated']
|
29
|
-
def session
|
30
|
-
@integrated_session ||= IntegratedSession.new(super, global_session)
|
31
|
-
return @integrated_session
|
41
|
+
global_session_update_cookie
|
42
|
+
#give the Rails app a chance to handle the exception
|
43
|
+
raise e
|
32
44
|
end
|
33
45
|
end
|
34
46
|
|
35
47
|
def global_session_update_cookie
|
36
|
-
return unless @global_session
|
37
48
|
name = Configuration['cookie']['name']
|
38
49
|
domain = Configuration['cookie']['domain']
|
39
50
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
options.merge!(:value => value, :expires => expires)
|
50
|
-
rescue Exception => e
|
51
|
-
logger.error "#{e.class.name}: #{e.message} (at #{e.backtrace[0]})" if logger
|
51
|
+
begin
|
52
|
+
if @global_session && @global_session.valid?
|
53
|
+
value = @global_session.to_s
|
54
|
+
expires = Configuration['ephemeral'] ? nil : @global_session.expired_at
|
55
|
+
|
56
|
+
unless (cookies[name] == value)
|
57
|
+
#Update the cookie only if its value has changed
|
58
|
+
cookies[name] = {:value => value, :domain=>domain, :expires=>expires}
|
59
|
+
end
|
52
60
|
end
|
53
|
-
end
|
54
61
|
|
55
|
-
|
62
|
+
raise HasGlobalSession::InvalidSession, "buahahaha" if params[:moo]
|
63
|
+
rescue Exception => e
|
64
|
+
#silently recover from any error by wiping the cookie
|
65
|
+
cookies[name] = {:value=>nil, :domain=>domain, :expires=>Time.at(0)}
|
66
|
+
#give the Rails app a chance to handle the exception
|
67
|
+
raise e
|
68
|
+
end
|
56
69
|
end
|
57
70
|
|
58
71
|
def log_processing
|
data/rails/init.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_global_session
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 49
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 7
|
10
|
+
version: 0.8.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tony Spataro
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-28 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|