Subscribe to RSS Subscribe to Comments

Alan Blaine Whitney

Cake 1.2 Final Auth Problems

I had auth working in 1.2RC3 just fine. What I wanted was all of the non-admin stuff to not need auth, but all of the admin stuff to have auth. Here is what my code used to look like

	function beforeFilter() {
		$this->Auth->allow('*');
		if (isset($this->params['admin'])) {
 			$this->Auth->deny("*");
		}
       }

That didn’t work in 1.2 final, here was the modification I had to make to get it working again.

	function beforeFilter() {
		$this->Auth->allow('*'); // Allow Everything by default
		$admin = (Configure::read('Routing.admin'));
		$strlen = strlen($admin);
		foreach ($this->Auth->allowedActions as $key) { 
			if (substr($key, 0, $strlen) == $admin) { 
				$this->Auth->deny($key); // Disable an admin_ like action
			}
		}
 
		if (is_a($this, "UsersController")) { 
			$this->Auth->deny('login');
		}
 
		if (isset($this->params['admin'])) { 
			$this->layout='admin';
		}
 
		if ($this->RequestHandler->isAjax()) { 
			$this->layout='ajax';
		}
    }

That seemed to fix it up. Go figure.

Cake 1.2RC3 to Final

Recently the cake 1.2 has been released.  On several of my applications I have upgrading all along the 1.2 release cycle.  Here are my tweaks that I needed to do from RC3 to 1.2 Final.

To start the upgrade, I simply swapped out my cake directory for the new one.  Dropped the tmp dir with this command.

find app/tmp/ -name ‘cake*’ | xargs rm

For the most part it worked right off the back.  The only problem I had was to switch some things in my “app/app_controller.php”.  In RC3, if it was an ajax request, it automatically switched to an ajax layout.  It stopped doing that in RC4 and final.  So I when to put functionality back in.

To start I added the request handler component and use beforeFilter().

	var $components = array('RequestHandler');
 
	function beforeFilter() {
		if ($this->RequestHandler->isAjax()) {
			$this->layout='ajax';
		}
    }

I actually had several things happening in my ‘app/app_controller.php’ already, here is my actual file.

	var $components = array('Auth', 'Email', 'RequestHandler');
 
	function beforeFilter() {
        $this->Auth->fields = array('username'=>'username', 'password' => 'password');
		$this->Auth->loginAction = array('admin' => false, 'controller' => 'users', 'action' => 'login');
		$this->Auth->allow('*');
 
		$this->set('navPoint', 'home');
 
		if (isset($this->params['admin'])) { 
			$this->layout='admin';
			$this->Auth->deny('*');
 
			// Lets set the sort order
			if (!$this->Session->check('sort')) {
				$this->Session->write('sort', 'Application.date_created DESC');
			}
		}
 
		if ($this->RequestHandler->isAjax()) { 
			$this->layout='ajax';
		}
    }

Based on FluidityTheme Redesigned by Kaushal Sheth Sponsored by Send Flowers