Example #1
0
 public function invoke()
 {
     $filter = new MUserFilter();
     $filter->oauth2Judge();
     //check user auth
     $user = MUserManager::getInstance()->getCurrentUser();
     $userId = $user["id"];
     $user = MiniUser::getInstance()->getUser($userId);
     if ($user["is_admin"] !== true) {
         throw new MiniException(1200);
     }
     parent::invoke();
 }
Example #2
0
 /**
  * 控制器执行主逻辑函数
  * @param null $uri
  * @throws MException
  * @return mixed $value 返回最终需要执行完的结果
  */
 public function invoke($uri = null)
 {
     // 解析控制器中对应操作名称
     $urlManager = new MUrlManager();
     $urlArray = $urlManager->parseActionFromUrl();
     if ($urlArray === false) {
         throw new MException(Yii::t('api', '{class} do not call an action', array('{class}' => get_class($this))));
     }
     $action = $urlArray["action"];
     $this->commonUri = $urlArray["uri"];
     self::$namespace = "api.{$action}";
     // 进行程序执行之前首先进行oauth用户身份信息验证
     // 排除指定動作可以匿名訪問
     $canAnonymous = false;
     if ($action == "info" || $action == "report") {
         $canAnonymous = true;
     }
     if ($action == "link") {
         $parts = explode("/", $this->commonUri);
         $subAction = $parts[2];
         if ($subAction == "selected") {
             $canAnonymous = true;
         }
     }
     if ($canAnonymous) {
         header('Access-Control-Allow-Origin: *');
         header('Access-Control-Allow-Methods: POST');
     }
     if (!$canAnonymous) {
         $filter = new MUserFilter();
         $filter->invoke($this->commonUri);
         // 过滤器,检查空间剩余
         $spaceFilter = new MActionFilter();
         $spaceFilter->action = $action;
         $spaceFilter->invoke($this->commonUri);
         // 修改在线用户状态
         $this->user = MUserManager::getInstance()->getCurrentUser();
         $this->device = MUserManager::getInstance()->getCurrentDevice();
         //更新设备在线状态
         MiniOnlineDevice::getInstance()->setOnlineDeviceValue($this->user["id"], $this->user["appId"], $this->device["id"]);
     }
     $this->{$action}();
 }
Example #3
0
 /**
  * 初始化用户会话信息
  */
 protected function initSession()
 {
     //初始化用户信息
     $filter = new MUserFilter();
     $filter->oauth2Judge();
 }