Commit 4488de24a5dde7bc37071837fd675a5a06454642
1 parent
520d07a0
Exists in
master
and in
29 other branches
Revert "Remove Rails 2.1 handling code from noosfero HTTP caching code"
This reverts commit 0fcf86d44896774ec82af0ea41ac6c61a95a3485.
Showing
1 changed file
with
34 additions
and
0 deletions
Show diff stats
vendor/plugins/noosfero_caching/init.rb
@@ -2,6 +2,8 @@ module NoosferoHttpCaching | @@ -2,6 +2,8 @@ module NoosferoHttpCaching | ||
2 | 2 | ||
3 | def self.included(c) | 3 | def self.included(c) |
4 | c.send(:after_filter, :noosfero_set_cache) | 4 | c.send(:after_filter, :noosfero_set_cache) |
5 | + c.send(:before_filter, :noosfero_session_check_before) | ||
6 | + c.send(:after_filter, :noosfero_session_check_after) | ||
5 | end | 7 | end |
6 | 8 | ||
7 | def noosfero_set_cache | 9 | def noosfero_set_cache |
@@ -25,6 +27,38 @@ module NoosferoHttpCaching | @@ -25,6 +27,38 @@ module NoosferoHttpCaching | ||
25 | end | 27 | end |
26 | end | 28 | end |
27 | 29 | ||
30 | + def noosfero_session_check_before | ||
31 | + return if params[:controller] == 'account' | ||
32 | + headers["X-Noosfero-Auth"] = (session[:user] != nil).to_s | ||
33 | + end | ||
34 | + | ||
35 | + def noosfero_session_check_after | ||
36 | + if headers['X-Noosfero-Auth'] == 'true' | ||
37 | + # special case: logout | ||
38 | + if !session[:user] | ||
39 | + session.delete | ||
40 | + end | ||
41 | + else | ||
42 | + # special case: login | ||
43 | + if session[:user] | ||
44 | + headers['X-Noosfero-Auth'] = 'true' | ||
45 | + end | ||
46 | + end | ||
47 | + end | ||
48 | + | ||
49 | +end | ||
50 | + | ||
51 | +class ActionController::CgiResponse | ||
52 | + | ||
53 | + def out_with_noosfero_session_check(output = $stdout) | ||
54 | + if headers['X-Noosfero-Auth'] == 'false' | ||
55 | + @cgi.send(:instance_variable_set, '@output_cookies', nil) | ||
56 | + end | ||
57 | + headers.delete('X-Noosfero-Auth') | ||
58 | + out_without_noosfero_session_check(output) | ||
59 | + end | ||
60 | + alias_method_chain :out, :noosfero_session_check | ||
61 | + | ||
28 | end | 62 | end |
29 | 63 | ||
30 | if Rails.env != 'development' | 64 | if Rails.env != 'development' |