AuthController.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\admin\controller\auth;
  3. use app\admin\service\auth\AuthService;
  4. use app\admin\validate\auth\AuthValidate;
  5. use app\model\SysUser;
  6. use support\Redis;
  7. use support\Request;
  8. use Tinywan\Jwt\JwtToken;
  9. class AuthController
  10. {
  11. public $notNeedLogin = ['login'];
  12. public function login(Request $request)
  13. {
  14. $validate = new AuthValidate();
  15. if (!$validate->scene('login')->check($request->post())) {
  16. return json_fail($validate->getError());
  17. }
  18. return AuthService::login($request->post());
  19. }
  20. public function logout(Request $request)
  21. {
  22. try {
  23. $userId = JwtToken::getCurrentId();
  24. SysUser::where('user_id',$userId)->update(['user_login_status'=>"OFFLINE"]);
  25. Redis::del("JWT:TOKEN:admin:".$userId);
  26. }catch (\Exception $e){
  27. dump($e->getMessage());
  28. return json_fail('退出登录失败');
  29. }
  30. return json_success('退出登录成功');
  31. }
  32. /**
  33. * @Desc 刷新token
  34. * @Author Gorden
  35. * @Date 2024/2/21 17:10
  36. *
  37. * @return \support\Response
  38. */
  39. public function refreshToken()
  40. {
  41. return AuthService::refreshToken();
  42. }
  43. public function userInfo(Request $request)
  44. {
  45. return AuthService::userInfo($request);
  46. }
  47. }