Kullanıcılarım (user_levels) kullanıcı masasına (user_level_id) bağlı bir tablo var. Seviye 5 yönetici.cakePHP isAuthorized not
Bazı eylemlerin izlenmesini ve anlaşılmasını sınırlamak istiyorum. Bunu, Yetkilendirilmiş ile yapabilirim. Kitaba göre gittim ve doğru yaptığımdan eminim, ama işe yaramıyor. Oturum açmış olan herhangi bir kullanıcının, yetkisiz olduğu halde inkar etmeme rağmen herhangi bir eyleme erişmesine izin verir. Sadece isAuthorized()
kullanmak sadece AuthComponent anlatmak için yapılandırma eksik olduğunu
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);
}
Hangi kitabı takip ediyorsunuz? – Bahdeng