Exemplo n.º 1
0
 public function init()
 {
     parent::init();
     $currentRequest = '/' . strtolower(implode('/', [$this->_request->module, $this->_request->controller, $this->_request->action]));
     $this->getView()->currentRequest = $currentRequest;
     if ($this->checkAuthorization && $this->userInfo) {
         $rbacManage = \Core\ServiceLocator::getInstance()->get('rbacManage');
         if (!$rbacManage->isAdmin($this->userInfo['name'])) {
             $authInfo = $rbacManage->checkAuthorization($this->userInfo['id'], $currentRequest);
             if ($authInfo == false) {
                 throw new \Exception('没有节点访问权限');
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * 适配默认后台样式的菜单列表
  * @param $userInfo
  * @param $currentRequet 当前请求权限节点
  * @return string
  */
 public static function builtMenu($userInfo, $currentRequet)
 {
     //TODO::可以根据业务实现缓存菜单文件
     $rbacManage = \Core\ServiceLocator::getInstance()->get('rbacManage');
     $itemGroup = $rbacManage->getItemsGroup('*', null);
     $userPermissionIds = [];
     foreach ($rbacManage->userPermissions as $ps) {
         $userPermissionIds[] = $ps['item_id'];
     }
     $menuHtml = '';
     PC::debug($itemGroup);
     foreach ($itemGroup as $item) {
         if (!isset($item['sub'])) {
             continue;
         }
         $shtml = '';
         $liActive = '';
         foreach ($item['sub'] as $subNode) {
             //管理员显示所有菜单
             if (!$rbacManage->isAdmin($userInfo['name'])) {
                 if (!in_array($subNode['id'], $userPermissionIds)) {
                     continue;
                 }
             }
             if ($subNode['show'] == RbacItemModel::ITEM_SHOW_NOT) {
                 continue;
             }
             $subLiActive = '';
             if ($currentRequet == strtolower($subNode['title'])) {
                 $liActive = $subLiActive = 'active';
             }
             $shtml .= "<li class='{$subLiActive}'><a href=\"{$subNode['title']}\"><i class=\"fa fa-circle-o text-aqua\"></i><span>{$subNode['desc']}</span></a></li>";
         }
         if (!$shtml) {
             continue;
         }
         $menuHtml .= "<li class=\"treeview {$liActive}\">\n                            <a href=\"#\"><i class=\"fa fa-th\"></i><span>{$item['desc']}</span><i class=\"fa fa-angle-left pull-right\"></i></a>\n                                <ul class=\"treeview-menu\">" . $shtml . "</ul>\n                          </li>";
     }
     return $menuHtml;
 }
Exemplo n.º 3
0
 public function init()
 {
     parent::init();
     $this->rbacManage = \Core\ServiceLocator::rbacManage();
 }