Permalink
Browse files

Closes #695. Fix for cookie detection.

Need to set a parameter and redirect page in order to test cookies and
distinguish between an expired session.
  • Loading branch information...
1 parent 9bed3de commit 4b913662afefec5b95beec53327aadd251258de0 @cy cy committed with jerboaa Jan 30, 2012
Showing with 18 additions and 7 deletions.
  1. +5 −0 app/controllers/main_controller.rb
  2. +13 −7 lib/cookie_detection.rb
@@ -50,6 +50,11 @@ def login
if !cookies_enabled
flash[:login_notice] = I18n.t(:cookies_off)
return
+ else
+ if !params[:cookieTest].nil?
+ # remove the :cookieTest => "currentlyTesting" parameter after testing for cookies by redirecting
+ redirect_to :controller => "main", :action => "login"
+ end
end
@current_user = current_user
View
@@ -6,12 +6,18 @@ module CookieDetection
# true if cookies are enabled, false otherwise.
def cookies_enabled
- return true unless cookies["cookieTest"].blank?
- cookies["cookieTest"] = Time.now
- session[:return_to] = request.fullpath
- if cookies["cookie_test"].blank?
- return false
- end
- return true
+ if cookies[:cookieTest].blank?
+ if params[:cookieTest].nil?
+ cookies[:cookieTest] = Time.now
+ # we need to redirect in order to test, otherwise cookies[] will not be blank even if no actual cookie exists because cookies[] was set locally
+ # send a parameter, "currentlyTesting" to same controller, and attempt to write cookie again
+ redirect_to :controller => "main", :action => "login", :cookieTest => "currentlyTesting"
+ else
+ # if the parameter cookieTest is set, then we have already tried to write a cookie and it is still empty. Cookies are off.
+ return false
+ end
+ else
+ return true
+ end
end
end

0 comments on commit 4b91366

Please sign in to comment.