CakePHP - Use jQuery to check if user is logged in thru Auth -
how can find out if user logged in cakephp thru auth component using jquery. if user logged in allow action execute if not display alert asking user 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 logged in vote on comment'); } }); }); </script>
assuming have commentscontroller action check_login()
public function check_login() { // $this->auth->user() returns null or user info logged in user if ($this->auth->user()) { // user logged in echo success ... } else { // user not logged in echo failure ... } }
Comments
Post a Comment