Exemplo n.º 1
0
 /**
  * 控制器执行主逻辑函数
  */
 public function invoke($uri = null)
 {
     // 调用父类初始化函数,注册自定义的异常和错误处理逻辑
     parent::init();
     $path = explode('?', $uri);
     $parts = array_slice(explode('/', $path[0]), 2);
     if ($parts[0] === "authorize") {
         $oauth = new PDOOAuth2();
         if ($_POST) {
             $oauth->finishClientAuthorization($_POST["accept"] == "Yep", $_POST);
         }
         $auth_params = $oauth->getAuthorizeParams();
         $inputs = "";
         foreach ($auth_params as $k => $v) {
             $inputs = $inputs . '<input type="hidden" name="' . $k . '" value="' . $v . '" />';
         }
         $content = '<html>' . '<head>Authorize</head>' . '<body>' . '<form method="post" action="http://web.miniyun.cn/miniyun_oauth2/api.php/1/oauth2/authorize">' . $inputs . 'Do you authorize the app to do its thing?' . '<p>' . ' <input type="submit" name="accept" value="Yep" />' . '<input type="submit" name="accept" value="Nope" />' . ' </p>' . '</form>' . '</body>' . ' </html>';
         echo $content;
     } elseif ($parts[0] === "token") {
         $oauth = new PDOOAuth2();
         $token = $oauth->grantAccessToken();
         #添加登陆日志
         $deviceId = $oauth->getVariable("device_id");
         MiniLog::getInstance()->createLogin($deviceId);
         #返回site_id,便于与cloud.miniyun.cn通信
         $token["site_id"] = MiniSiteUtils::getSiteID();
         echo json_encode($token);
     }
 }
Exemplo n.º 2
0
 /**
  * 用户登录
  * @return array|bool
  * @throws
  */
 public function oauth2()
 {
     $isExtend = apply_filters("license_expired");
     if ($isExtend === 1) {
         $userName = MiniHttp::getParam("username", "");
         if ($userName !== "admin") {
             throw new MiniException(440);
         }
     }
     $oauth = new PDOOAuth2();
     $token = $oauth->grantAccessToken();
     #添加登陆日志
     $deviceId = $oauth->getVariable("device_id");
     MiniLog::getInstance()->createLogin($deviceId);
     #返回site_id,便于与cloud.miniyun.cn通信
     $token["site_id"] = MiniSiteUtils::getSiteID();
     return $token;
 }