How can I find out if a user is logged in CakePHP thru the Auth component using jQuery. If a user is logged in allow the action to execute if not display an alert asking the user to log in.
<script>
$(document).ready(function(){
$(".voteup").click(function() {
// var isLoggedIn = ... code needed
if(isLoggedIn){
var Id = $(this).children("p").text();
$(this).children("#article_thumbsUp").load("/comments/voteup/"+Id);
}else{
alert('You must be logged in to vote on a comment');
}
});
});
</script>
Assuming you have a
CommentsControllerwith an actioncheck_login()