ChannelUserController.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Http\Controllers\Channel;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Channel\ChannelUserService;
  5. use Illuminate\Http\Request;
  6. use App\Consts\ErrorConst;
  7. use App\Libs\Utils;
  8. use App\Facade\Site;
  9. use App\Libs\ApiResponse;
  10. use App\Exceptions\ApiException;
  11. class ChannelUserController extends Controller
  12. {
  13. use ApiResponse;
  14. private $channelUserService;
  15. public function __construct(ChannelUserService $channelUserService)
  16. {
  17. $this->channelUserService = $channelUserService;
  18. }
  19. /**
  20. * 登录
  21. *
  22. * @param Request $request
  23. * @return mixed
  24. * @throws ApiException
  25. */
  26. public function login(Request $request)
  27. {
  28. $all = $request->all();
  29. $account = trim(getProp($all, 'account'));
  30. $password = trim(getProp($all, 'password'));
  31. if (strlen($account) < 1 || strlen($password) < 1) {
  32. Utils::throwError(ErrorConst::PARAM_ERROR_CODE);
  33. }
  34. // 登录
  35. $user = $this->channelUserService->login($account, $password);
  36. return $this->success($user);
  37. }
  38. /**
  39. * 退出登录
  40. *
  41. * @return mixed
  42. */
  43. public function logout()
  44. {
  45. // 当前登录用户
  46. $uid = Site::getUid();
  47. // 退出
  48. // $result = $this->channelUserService->logout($uid);
  49. $result = true;
  50. return $this->success(compact('result'));
  51. }
  52. /**
  53. * 修改密码
  54. *
  55. * @param Request $request
  56. * @return mixed
  57. * @throws ApiException
  58. */
  59. public function resetPassword(Request $request)
  60. {
  61. // 当前登录用户
  62. $uid = Site::getUid();
  63. $newPassword = trim($request->get('new_password', ''));
  64. if (strlen($newPassword) < 1) {
  65. Utils::throwError(ErrorConst::PARAM_ERROR_CODE);
  66. }
  67. // 退出
  68. $result = $this->channelUserService->resetPassword($uid, $newPassword);
  69. return $this->success(compact('result'));
  70. }
  71. }