User.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\Orders;
  4. use app\api\service\auth\ApiAuthService;
  5. use app\api\validate\User as UserValidate;
  6. use think\exception\ValidateException;
  7. use think\Cache;
  8. class User extends Base
  9. {
  10. protected $noNeedLogin = ['login'];
  11. public function userinfo(ApiAuthService $authService)
  12. {
  13. try{
  14. dump($this->userinfo);die;
  15. $user = $authService->userinfo();
  16. }catch (ValidateException $e) {
  17. return $this->error($e->getError());
  18. }catch (\Exception $e){
  19. return $this->error($e->getMessage());
  20. }
  21. return $this->success('ok', $user);
  22. }
  23. public function login(ApiAuthService $authService)
  24. {
  25. $data = $this->request->post();
  26. try{
  27. validate(UserValidate::class)->scene('login')->check($data);
  28. $user = $authService->login($data['username'],$data['password']);
  29. }catch (ValidateException $e) {
  30. return $this->error($e->getError());
  31. }catch (\Exception $e){
  32. return $this->error($e->getMessage());
  33. }
  34. return $this->success('ok', $user);
  35. }
  36. }