From a7705cac753e0b9188410cd528f5da7334c96471 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Tue, 23 Apr 2024 11:13:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=80=E5=87=BA=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=90=8E=E7=9A=84=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kqapi/security/handler/DefaultLogoutSuccessHandler.java | 4 ++-- .../com/ningdatech/kqapi/user/controller/UserAuthController.java | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/security/handler/DefaultLogoutSuccessHandler.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/security/handler/DefaultLogoutSuccessHandler.java index e24d0d7..904a0c4 100644 --- a/kq-vas-api/src/main/java/com/ningdatech/kqapi/security/handler/DefaultLogoutSuccessHandler.java +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/security/handler/DefaultLogoutSuccessHandler.java @@ -1,7 +1,7 @@ package com.ningdatech.kqapi.security.handler; import com.fasterxml.jackson.databind.ObjectMapper; -import com.ningdatech.basic.model.ApiResponse; +import com.ningdatech.kqapi.user.controller.UserAuthController; import org.springframework.context.annotation.Primary; import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; @@ -30,6 +30,6 @@ public class DefaultLogoutSuccessHandler implements LogoutSuccessHandler { throws IOException { // 退出成功后返回 和前端约定的Json response.setContentType("application/json;charset=UTF-8"); - response.getWriter().write(objectMapper.writeValueAsString(ApiResponse.ofSuccess())); + response.getWriter().write(objectMapper.writeValueAsString(UserAuthController.LOGOUT_RET)); } } diff --git a/kq-vas-api/src/main/java/com/ningdatech/kqapi/user/controller/UserAuthController.java b/kq-vas-api/src/main/java/com/ningdatech/kqapi/user/controller/UserAuthController.java index 45cef3d..d13972a 100644 --- a/kq-vas-api/src/main/java/com/ningdatech/kqapi/user/controller/UserAuthController.java +++ b/kq-vas-api/src/main/java/com/ningdatech/kqapi/user/controller/UserAuthController.java @@ -2,6 +2,7 @@ package com.ningdatech.kqapi.user.controller; import com.fasterxml.jackson.databind.ObjectMapper; +import com.ningdatech.basic.model.ApiResponse; import com.ningdatech.kqapi.common.constant.BizConst; import com.ningdatech.kqapi.common.util.StrPool; import com.ningdatech.kqapi.security.constant.AuthConst; @@ -31,6 +32,9 @@ public class UserAuthController { private final ObjectMapper objectMapper; + public static final ApiResponse LOGOUT_RET = ApiResponse.of(HttpStatus.UNAUTHORIZED.value(), "已退出登录"); + + @PostMapping(value = "/login/password", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) @ApiOperation(value = "账号密码的登陆方式") @ApiImplicitParams({ @@ -70,8 +74,8 @@ public class UserAuthController { cookie.setPath(request.getContextPath() + "/"); cookie.setMaxAge(AuthConst.SESSION_EXPIRED); response.addCookie(cookie); - response.setStatus(HttpStatus.UNAUTHORIZED.value()); - response.getWriter().write(objectMapper.writeValueAsString(BizConst.UNAUTHENTICATED)); + response.setStatus(HttpStatus.OK.value()); + response.getWriter().write(objectMapper.writeValueAsString(LOGOUT_RET)); } }