Auth.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\api\controller\v1\taxiUser;
  3. use app\common\controller\BaseController;
  4. use app\http\IResponse;
  5. use Lettered\Support\Auth as IAuth;
  6. use think\App;
  7. class Auth extends BaseController
  8. {
  9. protected $auth;
  10. /**
  11. * Auth constructor.
  12. * @param App $app
  13. * @param IAuth $auth
  14. */
  15. public function __construct(App $app, IAuth $auth)
  16. {
  17. parent::__construct($app);
  18. $this->auth = $auth;
  19. }
  20. /**
  21. * 司机端登录
  22. *
  23. * @return \think\response\Json
  24. * @throws \Lettered\Support\Exceptions\FailedException
  25. */
  26. public function login()
  27. {
  28. // 接收数据
  29. $param = $this->request->param();
  30. // 内置验证
  31. $valid = $this->validate($param, [
  32. 'mobile|手机号' => 'require|mobile',
  33. 'password|密码' => 'require',
  34. ]);
  35. // 错误
  36. if (true !== $valid){
  37. return IResponse::failure($valid);
  38. }
  39. // attempt
  40. $token = $this->auth->guard('taxi_user')->attempt($param);
  41. return $token ? IResponse::success([
  42. 'token' => 'Bearer ' . $token,
  43. ], '登录成功') : IResponse::failure('登录失败');
  44. }
  45. }