【发布时间】:2011-10-28 21:45:04
【问题描述】:
我直接使用 kohana 指南中的代码来根据登录凭据保护网站
问题是代码似乎只检查用户是否登录并且不区分角色。
如何修改此脚本以仅允许管理员访问此操作
在基本控制器中我有代码
public $assert_auth = FALSE;
public $assert_auth_actions = FALSE;
public function before()
{
parent::before();
$this->_user_auth();
}
protected function _user_auth()
{
$action_name = Request::instance()->action;
if (($this->assert_auth !== FALSE && Auth::instance()->logged_in($this->assert_auth) === FALSE)
|| (is_array($this->assert_auth_actions) && array_key_exists($action_name, $this->assert_auth_actions)
&& Auth::instance()->logged_in($this->assert_auth_actions[$action_name]) === FALSE))
{
if (Auth::instance()->logged_in())
{
Request::instance()
->redirect('');
}
else
{
Request::instance()
->redirect('admin/login');
}
}
在管理页面的控制器中有代码
public $assert_auth_actions = array(
'index' => array('login')
);
【问题讨论】:
标签: php model-view-controller orm kohana