本文整理汇总了PHP中ACL::isAllowed方法的典型用法代码示例。如果您正苦于以下问题:PHP ACL::isAllowed方法的具体用法?PHP ACL::isAllowed怎么用?PHP ACL::isAllowed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACL
的用法示例。
在下文中一共展示了ACL::isAllowed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkAcl
/**
* @param MvcEvent $e
*/
public function checkAcl(MvcEvent $e)
{
$route = $e->getRouteMatch();
$controller = $route->getParam('controller');
$action = $route->getParam('action');
if (!$this->acl->isAllowed($controller, $action)) {
$url = $e->getRouter()->assemble(array('controller' => 'index', 'action' => 'non-autorise'), array('name' => 'accueil'));
/** @var Response $response */
$response = $e->getResponse();
$response->getHeaders()->addHeaderLine('Location', $url);
$response->setStatusCode(302);
$response->sendHeaders();
}
}
示例2: authenticate
static function authenticate($resource = '', $permissions = '')
{
$ci =& get_instance();
$ci->form_validation->set_rules('token', 'token', 'required');
$validated = $ci->form_validation->run();
if ($validated) {
$token = $ci->input->post('token');
$token = JWT::decode($token, $ci->config->item('jwt_key'));
if ($token == false) {
$output['status'] = false;
$output['errors'] = '{"type": "unathenticated"}';
if (array_key_exists('errors', $output)) {
$errors = explode("\n", $output['errors']);
foreach ($errors as $key => $error) {
$errors[$key] = json_decode($error);
}
$output['errors'] = $errors;
}
$ci->load->view('json', array('output' => $output));
} else {
$acl = new ACL();
if (!empty($permissions) && !$acl->isAllowed($token->id, $resource, $permissions)) {
$token = false;
$output['status'] = false;
$output['errors'] = '{"type": "access"}';
if (array_key_exists('errors', $output)) {
$errors = explode("\n", $output['errors']);
foreach ($errors as $key => $error) {
$errors[$key] = json_decode($error);
}
$output['errors'] = $errors;
}
$ci->load->view('json', array('output' => $output));
return false;
}
return $token;
}
} else {
$output['status'] = false;
$output['errors'] = validation_errors();
if (array_key_exists('errors', $output)) {
$errors = explode("\n", $output['errors']);
foreach ($errors as $key => $error) {
$errors[$key] = json_decode($error);
}
$output['errors'] = $errors;
}
$ci->load->view('json', array('output' => $output));
return false;
}
}