我在OrdersController中使用了Auth组件,如下所示:
ParseUser user = new ParseUser();
当我尝试登录并且用户名和密码匹配时,它会重定向到adminc / deshboard,并显示以下错误消息:
public $components = array(
'Session',
'Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array(
'username' => 'email', //Default is 'username' in the userModel
'password' => 'password' //Default is 'password' in the userModel
),
'userModel' => 'Agent'
)
),
'loginAction' => array(
'controller' => 'admins',
'action' => 'login'
),
'loginRedirect' => array('controller' => 'admins', 'action' => 'deshboard'),
'logoutRedirect' => array('controller' => 'admins', 'action' => 'login'),
'authError' => "You can't acces that page",
'authorize' => 'Controller'
)
);
public function beforeFilter() {
parent::beforeFilter();
// Allow users to register and logout.
$this->Auth->allow('login','index');
}
我搜索谷歌几个小时没有解决方案。我为此错误做了什么?谢谢你的时间。
答案 0 :(得分:3)
您需要实施isAuthorized()
,如下所示:
class OrdersController extends Controller {
//...
public function isAuthorized($user) {
//auth check
//return boolean
}
//...
}
有关详细信息,请参阅http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html。