CakePHP function isAuthorized -
i following instructions directly cakebook hide things common user on administrative system. possible administrator access pages. however, unable run user accesses can see all. following code:
public function beforefilter(){ $this->auth->authenticate = array('form' => array( 'usermodel' => 'usuario', 'fields' => array( 'username' => 'login', 'password' => 'senha'))); $this->auth->loginaction = array( 'controller' => 'usuarios', 'action' => 'login'); parent::beforefilter(); } public function isauthorized($user) { if (isset($user['role']) && $user['role'] === 'admin') { return true; } return false; }
i'm not sure if understand correctly, i'll give try.
i have cleaned code, made indents , more readable (for me @ least). removed parent::beforefilter();. appcontroller.php:
public function beforefilter(){ // don't need line: parent::beforefilter(); $this->auth->authenticate = array('form' => array( 'usermodel' => 'usuario', 'fields' => array( 'username' => 'login', 'password' => 'senha' ) ) ); $this->auth->loginaction = array( 'controller' => 'usuarios', 'action' => 'login' ); } public function isauthorized($user) { if (isset($user['role']) && $user['role'] === 'admin') { return true; } return false; } now users admin role can access pages. if want user have access post comments, example of how let him. commentscontroller.php:
public function isauthorized($user) { // registered users can add comment if ($this->action === 'add') { return true; } return parent::isauthorized($user); } now admins can view every single page, registered user can see app/comments/add
Comments
Post a Comment