I have various image galleries for different users. For the most part the complete page may be cached. However I also want the following features:
If a user is logged in and visiting his own gallery, then the user can see an "x" delete link overlaying each image.
If a user is logged in and on someone else's gallery, then they can see overlays "thumb up", "thumb down" voting for each image.
If a user is NOT logged in, they can see the overlays for voting, however clicking on them will pop-up a login dialog.
The approach I have come up with is this:
The question is... what is the best way of determining the user's login status on a cached page? Can I use cookies over cached pages?
Would it work if I had a piece of javascript on the cached page that checked for a cookie value similar to this:
if ($.cookie("user_id") == 23) { //if user is owner of this gallery...
//reveal delete links, hide voting links
}
I hate to build something special to set that cookie... there should already exist some type of DEVISE cookie right? How do I access it?
Use $.cookie("user_id")
to set the cookie, use $.cookie("user_id", "23")
to set a cookie. You should beware of unauthenticated abuse, though: Every credential-less request that requires authentication should be rejected, or the purpose of logging in will be defeated.
If you want to check for the available cookies on your website, use this bookmarklet:
javascript:alert(document.cookie)