Мы используем компонент Auth. В настоящее время мы можем запретить пользователям, не вошедшим в систему, посещать нашу страницу «администратора» (adminhome.ctp). Но мы не можем понять, как сделать так, чтобы isAuthorized()
запретил посещение страницы и пользователям, не являющимся администраторами.
Внутри AppController:
public function beforeFilter() {
$this->Auth->allow('index', 'view', 'login', 'logout', 'display');
$this->Auth->authorize = array('Controller');
//$this->Auth->autoRedirect = false;
}
public function isAuthorized($user_id) {
$this->loadModel('User');
$user = $this->User->findById($this->Auth->user());
if ( $user['User']['role'] === 'admin') {
$this->Session->setFlash('isAuthorized');
return true;
}
$this->Session->setFlash('!isAuthorized');
return false;
}
Здесь beforeFilter() в PagesController:
function beforeFilter() {
$this->Auth->deny('adminhome');
}
Что мы делаем не так?