I'm kind of stuck here - I can write a hack to work around this but was wondering if there is a proper way to do this.
I am using Zend ACL to specify which pages are protected and require authentication. For example if the "UploadVideo.php" is a protected page - when a user clicks on a link to access that page - he is taken to the login page and after login is redirected back to UploadVideo.php page. So this all is taken care of and works fine.
Now on this other page - I have something like a "VOTE" button. A user can only cast vote if he is logged in.
Case 1
When the user is logged in - he clicks on the Vote button - I am using Jquery to call the action the following way:
$.post('/video/vote', {video_id:video_id}, function(data) {
if(data=="OK") .....
}
Now /video/vote is a protected resource and since the user is logged in - the vote action gets called which increases the vote count and sends back an "OK" message and the page is dynamically updated with the new vote count.
Case 2 The user is not logged in - he clicks on the vote button - since the page is protected - the login page is returned thru the ajax call in variable "data" Ideally, when the user is not logged in - the ajax call should not happen - the user should be redirected to the login page - after login he shud be redirected to the /video/vote action which will increment the vote count - and finally sent back to the page with the vote button
How do I handle this. I can write some hacks and check if user is logged in or not and depending upon that decide whether to make ajax call or redirect user but is that the best way to do this.
I dont know if I have clearly explained the problem.
Thanks for your time