/** * 控制器执行主逻辑函数 */ 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); } }
/** * 用户登录 * @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; }
/** * 清空所有登陆记录 */ public function cleanLog() { $userId = $this->user['id']; MiniLog::getInstance()->feignDeleteLogs($userId, ProfileBiz::TYPE); return true; }
/** * 为创建事件记录日志信息 * @param $user_id * @param $action * @param $path * @param $context */ private function createLogs($user_id, $action, $path, &$context) { if ($action == MConst::CREATE_FILE) { // // 如果是创建文件,记录path // $new = $path; } else { $new = $context; } $context = array($path, $new, $action); MiniLog::getInstance()->createOperateLog($user_id, serialize($context)); return $new; }