Jac*_*ble 4 php authentication cakephp
我试图使用isAuthorized()方法来检查管理标志,但似乎永远不会调用该函数.即使我将函数设置为始终返回false,它也允许任何用户.它似乎没有被调用.
我是否需要做更多的事情而不是设置$ this-> Auth-> authorize ='controller'?
来自/app/app_controller.php
class AppController extends Controller
{
var $components = array('Auth');
function beforeFilter()
{
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'pages', 'display' => 'home');
$this->Auth->logoutRedirect = '/';
$this->Auth->authorize = 'controller';
$this->Auth->userScope = array('User.active' => 1);
}
function isAuthorized()
{
if (strpos($this->action, "admin_") != false)
{
if ($this->Auth->user('isAdmin') == '0')
{
return false;
}
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
dr *_*ter 12
您应该检查是否覆盖了其他控制器中的Auth设置.
首先,要验证isAuthorized()是否正在调用,请尝试简单debug($this); die;地插入.
如果它没有死亡,你可能会在其他控制器中覆盖它(你错过了这个parent::isAuthorized()电话).
如果不是这样,那么你可能正在做同样的事情beforeFilter().