Created
January 3, 2012 21:12
-
-
Save ceeram/1556959 to your computer and use it in GitHub Desktop.
example for loggin in guests in CakePHP 2.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('Controller', 'Controller'); | |
class AppController extends Controller { | |
public $components = array( | |
'Auth' => array( | |
'authorize' => 'Controller', | |
), | |
'Session' | |
); | |
public function beforeFilter() { | |
if ($this->action != 'login' && !$this->Auth->user()) { | |
$this->Auth->login('guest'); | |
} | |
} | |
public function isAuthorized() { | |
$role = $this->Auth->user('role'); | |
if ($role == 'admin') { | |
return true; | |
} elseif ($role == 'user') { | |
if (in_array($this->action, array('edit', 'delete'))) { | |
return false; | |
} | |
return true; | |
} | |
if (in_array($this->action, array('index', 'view'))) { | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment