这可能是一个重复的问题,但是我已经遍历了所有其他答案,但没有一个对我有用:(
以下是我在AppController中的代码:
public $components = array(
'Auth',
'Session'
);
public function beforeFilter() {
$this->Auth->authorize = 'Controller';
$this->Auth->authenticate = array(
'Form' => array(
'fields' => array('username' => 'email', 'password' => 'password'),
'scope' => array('User.active' => 1),
'passwordHasher' => 'Blowfish'
)
);
}
public function isAuthorized($user) {
debug($this->request->params);
exit;
}
我没有在任何其他控制器中重写beforeFilter或isAuthorized函数。无论打开什么页面,我都不会调用isAuthorized函数,而是将我带到登录页面。请帮忙!
仅在成功通过身份验证后进行授权检查,请参阅AuthComponent::startup()
。
public function startup(Controller $controller) {
// ...
// authenticate first
if (!$this->_getUser()) {
return $this->_unauthenticated($controller);
}
// then authorize
if ($this->_isLoginAction($controller) ||
empty($this->authorize) ||
$this->isAuthorized($this->user())
) {
return true;
}
// ...
}
因此,解决方案可能应该是首先登录。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句