realm3: web applications

<List Articles>Public Pages - A Small CakePHP 1.2 AuthComponent Hack

Originally posted May 22, 2008

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.