1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace app\admin\controller\auth;
- use app\admin\service\auth\AuthService;
- use app\admin\validate\auth\AuthValidate;
- use app\model\SysUser;
- use support\Redis;
- use support\Request;
- use Tinywan\Jwt\JwtToken;
- class AuthController
- {
- public $notNeedLogin = ['login'];
- public function login(Request $request)
- {
- $validate = new AuthValidate();
- if (!$validate->scene('login')->check($request->post())) {
- return json_fail($validate->getError());
- }
- return AuthService::login($request->post());
- }
- public function logout(Request $request)
- {
- try {
- $userId = JwtToken::getCurrentId();
- SysUser::where('user_id',$userId)->update(['user_login_status'=>"OFFLINE"]);
- Redis::del("JWT:TOKEN:admin:".$userId);
- }catch (\Exception $e){
- dump($e->getMessage());
- return json_fail('退出登录失败');
- }
- return json_success('退出登录成功');
- }
- /**
- * @Desc 刷新token
- * @Author Gorden
- * @Date 2024/2/21 17:10
- *
- * @return \support\Response
- */
- public function refreshToken()
- {
- return AuthService::refreshToken();
- }
- public function userInfo(Request $request)
- {
- return AuthService::userInfo($request);
- }
- }
|