User.php 1022 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\api\controller;
  10. use app\api\model\User as UserModel;
  11. /**
  12. * 用户管理
  13. * Class User
  14. * @package app\api
  15. */
  16. class User extends Controller
  17. {
  18. /**
  19. * 用户自动登录
  20. * @return array
  21. * @throws \app\common\exception\BaseException
  22. * @throws \think\Exception
  23. * @throws \think\exception\DbException
  24. */
  25. public function login()
  26. {
  27. $model = new UserModel;
  28. return $this->renderSuccess([
  29. 'user_id' => $model->login($this->request->post()),
  30. 'token' => $model->getToken()
  31. ]);
  32. }
  33. /**
  34. * 当前用户详情
  35. * @return array
  36. * @throws \app\common\exception\BaseException
  37. * @throws \think\exception\DbException
  38. */
  39. public function detail()
  40. {
  41. // 当前用户信息
  42. $userInfo = $this->getUser();
  43. return $this->renderSuccess(compact('userInfo'));
  44. }
  45. }