| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace app\api\controller;
- use think\captcha\facade\Captcha;
- use app\api\service\auth\ApiAuthService;
- use app\api\validate\User as UserValidate;
- use think\exception\ValidateException;
- use think\Cache;
- class User extends Base
- {
- protected $noNeedLogin = ['login'];
- public function userinfo()
- {
- $user = $this->userinfo;
- return $this->success('ok', $user);
- }
- public function login(ApiAuthService $authService)
- {
- $data = $this->request->post();
- try{
-
- validate(UserValidate::class)->scene('login')->check($data);
- $user = $authService->login($data['username'],$data['password']);
- }catch (ValidateException $e) {
-
- return $this->error($e->getError());
- }catch (\Exception $e){
- return $this->error($e->getMessage());
- }
- return $this->success('ok', $user);
- }
- }
|