| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace App\Http\Controllers\Account;
- use App\Facade\Site;
- use App\Consts\ErrorConst;
- use App\Exceptions\ApiException;
- use App\Libs\ApiResponse;
- use App\Libs\Utils;
- use App\Services\Account\AccountService;
- use App\Transformer\Account\AccountTransformer;
- use Illuminate\Http\Request;
- use Illuminate\Routing\Controller as BaseController;
- use Illuminate\Support\Facades\Redis;
- use Illuminate\Support\Facades\Validator;
- class AccountController extends BaseController
- {
- use ApiResponse;
- protected $accountService;
- public function __construct(
- AccountService $accountService
- ) {
- $this->accountService = $accountService;
- }
- 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);
- }
- // 登录
- $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]);
- }
- public function userInfo()
- {
- // 登录
- $user = $this->accountService->userInfo();
- return $this->success($user);
- }
- }
|