Example #1
0
 /**
  * @param \Phalcon\Mvc\Dispatcher|\Phalcon\Mvc\DispatcherInterface $dispatcher
  * @return bool
  */
 public function beforeExecuteRoute($dispatcher)
 {
     $this->operator = new OperatorIdentity();
     $this->operator->cookies = $this->cookies;
     $this->operator->load();
     // 判断登录
     $moduleConfig = $this->di->get('moduleConfig');
     $controllerName = $dispatcher->getControllerName();
     $actionName = $dispatcher->getActionName();
     if ($controllerName == $moduleConfig->operator->login->controller && $actionName == $moduleConfig->operator->login->action) {
         return true;
     }
     if ($this->operator->isLogin()) {
         // 判断权限
         $result = OperatorGroupRight::verify($this->operator->group, $controllerName, $actionName, $dispatcher->getDI());
         // 权限不足,输出错误
         if (!$result) {
             $content = '';
             if ($this->request->isAjax()) {
                 $resp = new ResponseResult();
                 $resp->sendError(ResponseResultStatus::RIGHT_VERIFY_FAIL, '权限不足!');
                 $content = $resp->getContent();
             } else {
                 $content = '访问权限不足!';
             }
             $this->view->disable();
             echo $content;
         }
         return $result;
     }
     if ($this->request->isAjax()) {
         $resp = new ResponseResult();
         $resp->sendError(ResponseResultStatus::USER_TOKEN_EXPIRES, '未登录!');
         echo $resp->getContent();
     } else {
         $this->response->redirect($moduleConfig->operator->login->url);
     }
     $this->view->disable();
     return false;
 }
Example #2
0
 public function indexAction()
 {
     $this->response->redirect(GroupRight::loginToUrl($this->operator->group));
 }