| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- declare (strict_types = 1);
- namespace app\api\controller;
- use app\api\validate\User as UserValidate;
- use app\api\service\ApiAuthService;
- use think\annotation\route\Post;
- use think\exception\ValidateException;
- class User extends Api
- {
-
- protected $noNeedLogin = ['login'];
- public function userinfo(ApiAuthService $apiAuth)
- {
- $user= $apiAuth->userinfo();
- return $this->jsonSuccess('登录成功', $user);
- }
-
- //登录
- public function login(ApiAuthService $apiAuth)
- {
- $data=$this->request->post();
- try {
- validate(UserValidate::class)->scene('edit')->check($data);
- $ret = $apiAuth->login($data['username'], $data['password']);
- return $this->jsonSuccess('登录成功', $ret);
-
- } catch (ValidateException $e) {
- return $this->jsonError($e->getError());
- }catch (\Exception $e) {
-
- return $this->jsonError($e->getMessage());
- }
- }
-
- }
|