This project is read-only.

Is User Logged In (check in JQuery)

Topics: Customizing Orchard
Jan 27, 2012 at 1:34 AM

I am heavily customizing the comment post form, and want to ensure that the user is authenticated prior to submitting the post (I am hiding the "Name", "Email" "SiteUrl" additional fields via JQuery). I am wiring up gritter notifications to the results of the check.

I downloaded a jquery plugin for examining the cookie. I noticed the authentication cookie is ".ASPXAUTH", but that is http only, so i can't read it in javascript. Obviously if I edit the cookie and make it not http only via a cookie plugin to firefox, there's no problem with this approach. But I can't control whether that cookie is set server-side as http only...nor would i want to either, I suppose.

Is there a way to verify user authentication via an ajax request and then wire the callback result accordingly rather than reading a cookie?

If not, is there a way to downrender some hidden input that contains "true" or "false" as to whether the user is authenticated?

If none of these options seem pleasing to the platform designers, I am all ears to another approach.



Jan 27, 2012 at 2:54 AM

It's more normal to just hide the comments form and display a "you need to log in" link (which is what Comments does already if you disable anonymous commenting)

But if you really want to do this, it's easy to write a Controller that will return true/false depending on the Auth status. But that's kind of contrary to the point of client-side validation because it'll make the form submit take longer ...

Jan 27, 2012 at 3:16 AM
Edited Jan 27, 2012 at 3:30 AM

ok, that totally makes sense as a convention; i accept that. where in the admin would i disable anonymous commenting? having trouble finding it.


actually, no worries. found what i needed here. i'll just style this how i want it to look. thanks for the advice.