AccountController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace App\Http\Controllers\Account;
  3. use App\Facade\Site;
  4. use App\Consts\ErrorConst;
  5. use App\Exceptions\ApiException;
  6. use App\Libs\ApiResponse;
  7. use App\Libs\Utils;
  8. use App\Services\Account\AccountService;
  9. use App\Transformer\Account\AccountTransformer;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Routing\Controller as BaseController;
  12. use Illuminate\Support\Facades\Redis;
  13. use Illuminate\Support\Facades\Validator;
  14. class AccountController extends BaseController
  15. {
  16. use ApiResponse;
  17. protected $accountService;
  18. public function __construct(
  19. AccountService $accountService
  20. ) {
  21. $this->accountService = $accountService;
  22. }
  23. public function index(Request $request)
  24. {
  25. // 入口页面禁止缓存,保证每次更新后普通刷新即可加载最新版本
  26. return response()
  27. ->view('index')
  28. ->header('Cache-Control', 'no-store, no-cache, must-revalidate')
  29. ->header('Pragma', 'no-cache')
  30. ->header('Expires', '0')
  31. ->header('X-Accel-Expires', '0');
  32. }
  33. /**
  34. * 动漫音频管理平台入口
  35. *
  36. * @param Request $request
  37. * @return \Illuminate\Contracts\View\View
  38. */
  39. public function animeIndex(Request $request)
  40. {
  41. // 入口页面禁止缓存,保证每次更新后普通刷新即可加载最新版本
  42. return response()
  43. ->view('animeIndex')
  44. ->header('Cache-Control', 'no-store, no-cache, must-revalidate')
  45. ->header('Pragma', 'no-cache')
  46. ->header('Expires', '0')
  47. ->header('X-Accel-Expires', '0');
  48. }
  49. /**
  50. * 登录
  51. *
  52. * @param Request $request
  53. * @return mixed
  54. * @throws ApiException
  55. */
  56. public function login(Request $request)
  57. {
  58. $all = $request->all();
  59. $account = trim(getProp($all, 'account'));
  60. $passwd = trim(getProp($all, 'passwd'));
  61. if (strlen($account) < 1 || strlen($passwd) < 1) {
  62. Utils::throwError(ErrorConst::PARAM_ERROR_CODE);
  63. }
  64. // 登录
  65. $user = $this->accountService->login($account, $passwd);
  66. return $this->success($user);
  67. }
  68. /**
  69. * 退出登录
  70. *
  71. * @return mixed
  72. */
  73. public function logout()
  74. {
  75. // 当前登录用户
  76. $token = Site::getToken();
  77. // 退出
  78. $result = $this->accountService->logout($token);
  79. return $this->success(['success' => $result ? 1 : 0]);
  80. }
  81. public function userInfo()
  82. {
  83. // 登录
  84. $user = $this->accountService->userInfo();
  85. return $this->success($user);
  86. }
  87. }