| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace app\api\controller\v1\taxiUser;
- use app\common\controller\BaseController;
- use app\http\IResponse;
- use Lettered\Support\Auth as IAuth;
- use think\App;
- class Auth extends BaseController
- {
- protected $auth;
- /**
- * Auth constructor.
- * @param App $app
- * @param IAuth $auth
- */
- public function __construct(App $app, IAuth $auth)
- {
- parent::__construct($app);
- $this->auth = $auth;
- }
- /**
- * 司机端登录
- *
- * @return \think\response\Json
- * @throws \Lettered\Support\Exceptions\FailedException
- */
- public function login()
- {
- // 接收数据
- $param = $this->request->param();
- // 内置验证
- $valid = $this->validate($param, [
- 'mobile|手机号' => 'require|mobile',
- 'password|密码' => 'require',
- ]);
- // 错误
- if (true !== $valid){
- return IResponse::failure($valid);
- }
- // attempt
- $token = $this->auth->guard('taxi_user')->attempt($param);
- return $token ? IResponse::success([
- 'token' => 'Bearer ' . $token,
- ], '登录成功') : IResponse::failure('登录失败');
- }
- }
|