views:

129

answers:

1

I'm using the Auth component on my pages and I would like to show a login overlay when an Ajax action is called for which the user doesn't have permission.

Example:

User wants to edit a jeditable field, then when the users wants to change the value, he will first get a login/register overlay.

My current way is to check in the action for $_SESSION['Auth']['User'], however this seems to be very dirty and I want to do it in a clean way.

Currently my code is:

if(!$_SESSION['Auth']['User']) {

$this->layout = 'ajax';
$this->render('loginpopup');    
return;

}

I would love the input of more experienced users, I'm using Jquery as my javascript library. Thanks in advance!

+1  A: 

I don't know cake, but in terms of best practice, your application should probably have a universal helper method for accessing the session. The rails standard is current_user (which returns a user object if someone is logged in, and nil if not). Then you should wrap javascript to launch the login popup in a PHP conditional which calls that method.

floyd
Yes, CakePHP has $this->Auth(user) (I just found out, thanks :) ) So I assume you think reading this, and then wrapping the javascript would be the cleanest way to do so? If I use Auth to deny access to the action, then it gives back a nice 403 error, I thought maybe I can do something based on this? Already thanks for taking the time to answer me!
JanWillem