Ich habe eine Tabelle, die meine Benutzer (user_levels) auflistet, die mit der Tabelle users (user_level_id) verknüpft sind. Level 5 ist Administrator.cakePHP isAuthorized funktioniert nicht
Ich möchte bestimmte Aktionen zu sehen eingeschränkt werden und ich kann dies mit isAuthorized tun. Ich ging nach dem Buch und ich bin mir ziemlich sicher, dass ich es richtig gemacht habe, aber es funktioniert nicht. Es erlaubt allen eingeloggten Benutzern weiterhin auf eine der Aktionen zuzugreifen, obwohl ich dies in isAuthorized leugne.
Hier ist mein Code:
App Controller:public $components = array(
'Session',
'Auth' => array(
'loginAction' => array(
'controller' => 'users',
'action' => 'login',
),
'authError' => "Your username and password is incorrect, please try again.",
'authenticate' => array(
'Form' => array(
'scope' => array('User.user_status_id' => 1)
)
),
'redirect' => array("controller" => "users", "action" => "profile"),
'loginRedirect' => array("controller" => "users", "action" => "profile")
)
);
public function isAuthorized($user = null) {
if($this->Auth->user("user_level_id") == 5) {
return true;
}
// Default deny
return false;
}
public function beforeFilter() {
$this->Auth->allow("display");
if($this->Auth->loggedIn() == true) {
$this->set("user_name",$this->Auth->user("first_name")." ".$this->Auth->user("last_name"));
$this->set("loggedIn",true);
if($this->Auth->user("user_type_id") == 5) {
$this->set("navigation","navigation_admin");
} else {
$this->set("navigation","navigation_loggedin");
}
} else {
$this->set("loggedIn",false);
$this->set("navigation","navigation_notloggedin");
}
}
}
// Users Controller:
public function beforeFilter() {
$this->Auth->allow("login");
parent::beforeFilter();
}
public function isAuthorized($user = null) {
if($this->Auth->user("user_level_id") == 5) {
return true;
}
// Default deny
return parent::isAuthorized($user);
}
Welches Buch folgen Sie? – Bahdeng