User.php 913 B

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