| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace app\api\controller;
- use app\api\service\auth\MysqlAdapter;
- 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);
- }
- //退出登录
- public function logout()
- {
- MysqlAdapter::logout($this->userinfo['id']);
- return $this->success('ok');
- }
- }
|