| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace app\agent\controller;
- use app\common\controller\AgentController;
- use app\http\IResponse;
- class Auth extends AgentController
- {
- /**
- * 后台登录
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/3/16 11:57
- *
- * @return \think\response\Json
- * @throws \Lettered\Support\Exceptions\FailedException
- */
- public function login()
- {
- // 接收数据
- $param = $this->request->param();
- // 内置验证
- $valid = $this->validate($param, [
- 'username|用户名' => 'require',
- 'password|密码' => 'require',
- // 'captcha|验证码' => 'require|captcha:manage',
- ]);
- // 错误
- if (true !== $valid){
- return IResponse::failure($valid);
- }
- // attempt
- $token = $this->auth->attempt($param);
- return $token ? IResponse::success([
- 'token' => 'Bearer ' . $token,
- ], '登录成功') : IResponse::failure('登录失败');
- }
- }
|