Skip to content

Commit

Permalink
Closes #695. Fix for cookie detection.
Browse files Browse the repository at this point in the history
Need to set a parameter and redirect page in order to test cookies and
distinguish between an expired session.
  • Loading branch information
cy authored and jerboaa committed Mar 12, 2012
1 parent 9bed3de commit 4b91366
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/controllers/main_controller.rb
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions lib/cookie_detection.rb
Expand Up @@ -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.