accountService = $accountService; $this->captchaService = $captchaService; } public function index(Request $request) { // 入口页面禁止缓存,保证每次更新后普通刷新即可加载最新版本 return response() ->view('index') ->header('Cache-Control', 'no-store, no-cache, must-revalidate') ->header('Pragma', 'no-cache') ->header('Expires', '0') ->header('X-Accel-Expires', '0'); } /** * 动漫音频管理平台入口 * * @param Request $request * @return \Illuminate\Contracts\View\View */ public function animeIndex(Request $request) { // 入口页面禁止缓存,保证每次更新后普通刷新即可加载最新版本 return response() ->view('animeIndex') ->header('Cache-Control', 'no-store, no-cache, must-revalidate') ->header('Pragma', 'no-cache') ->header('Expires', '0') ->header('X-Accel-Expires', '0'); } /** * 登录 * * @param Request $request * @return mixed * @throws ApiException */ public function login(Request $request) { $all = $request->all(); $account = trim(getProp($all, 'account')); $passwd = trim(getProp($all, 'passwd')); if (strlen($account) < 1 || strlen($passwd) < 1) { Utils::throwError(ErrorConst::PARAM_ERROR_CODE); } // 图片验证码校验(config('captcha.enabled') 开启时生效) if (config('captcha.enabled')) { $this->captchaService->verify( (string)getProp($all, 'captcha_key'), (string)getProp($all, 'captcha_code') ); } // 登录 $user = $this->accountService->login($account, $passwd); return $this->success($user); } /** * 退出登录 * * @return mixed */ public function logout() { // 当前登录用户 $token = Site::getToken(); // 退出 $result = $this->accountService->logout($token); return $this->success(['success' => $result ? 1 : 0]); } /** * 刷新 token * * 通过 refresh_token 换取新的 token 与 refresh_token(token 过期后调用) * * @param Request $request * @return mixed * @throws ApiException */ public function refreshToken(Request $request) { $refreshToken = getProp($request->all(), 'refresh_token'); $user = $this->accountService->refreshToken($refreshToken); return $this->success($user); } public function userInfo() { // 登录 $user = $this->accountService->userInfo(); return $this->success($user); } /** * 修改账号(仅允许修改一次) * * @param Request $request * @return mixed * @throws ApiException */ public function updateAccount(Request $request) { $account = (string)getProp($request->all(), 'account', ''); $this->accountService->updateAccount((int)Site::getUid(), $account); return $this->success(['success' => 1]); } }