Public Pages - A Small CakePHP 1.2 AuthComponent Hack
Originally posted May 22, 2008
Brian Dailey is a LAMP-stack developer with a wide range of experience in the development world. Get in touch!
For more articles on the development trade, see the Blog.
The AuthComponent built into CakePHP 1.2 is a great way to manage user authentication with out re-inventing the wheel.
If you have read up on the documentation you'll noticed that there is an $allowedActions array that indicates which actions are available without logging in. But what if you want to authorize all actions except for any action using the 'admin' interface?
In that case, put this in your app_controller.php file:
function beforeFilter()
{
if (isset($this->params['admin'])) {
$this->checkSession();
} else {
$this->Auth->allowedActions = array('*');
}
}
Inside the checkSession() function you can stuff all of your usual code to authenticate the user.