用户登录退出接口
This commit is contained in:
parent
484e7fa450
commit
620e17854a
|
@ -7,6 +7,7 @@ import com.zjyr.beidouservice.pojo.dto.LoginRspDTO;
|
|||
import com.zjyr.beidouservice.pojo.dto.auth.UserLoginReqDTO;
|
||||
import com.zjyr.beidouservice.pojo.po.MulReturnType;
|
||||
import com.zjyr.beidouservice.service.UserAccountService;
|
||||
import com.zjyr.beidouservice.utils.UserRequestUtil;
|
||||
import com.zjyr.beidouservice.validation.TokenAuthInterface;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -16,6 +17,7 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
@ -48,14 +50,12 @@ public class AuthController {
|
|||
*/
|
||||
@PostMapping("/login")
|
||||
@ResponseBody
|
||||
public MyResp userLogin(@RequestBody UserLoginReqDTO userLoginReqDTO)
|
||||
public MyResp userLogin(@RequestBody UserLoginReqDTO userReqDTO)
|
||||
throws NoSuchAlgorithmException {
|
||||
LoginRspDTO rspInfo = LoginRspDTO.builder()
|
||||
.userName("username")
|
||||
.build();
|
||||
LoginRspDTO rspInfo = LoginRspDTO.builder().userName(userReqDTO.getUsername()).build();
|
||||
|
||||
// 登录
|
||||
MulReturnType<ErrorCode, String> ret = userAccountService.loginService(userLoginReqDTO.getUsername(), userLoginReqDTO.getPasswd());
|
||||
MulReturnType<ErrorCode, String> ret = userAccountService.loginService(userReqDTO.getUsername(), userReqDTO.getPasswd());
|
||||
//MulReturnType<ErrorCode, String> ret = userAccountService.loginService("admin", "2DC5B63023999B5BC57EB6B74B2232E3");
|
||||
|
||||
// 登录错误
|
||||
|
@ -87,13 +87,13 @@ public class AuthController {
|
|||
@PostMapping("/logout")
|
||||
@ResponseBody
|
||||
@TokenAuthInterface
|
||||
public MyResp<LoginRspDTO> userLogout() { // 注销用户登录
|
||||
LoginRspDTO rspInfo = LoginRspDTO.builder()
|
||||
.userName("username")
|
||||
.build();
|
||||
public MyResp<LoginRspDTO> userLogout(@RequestParam String username) { // 注销用户登录
|
||||
LoginRspDTO rspInfo = LoginRspDTO.builder().userName(username).build();
|
||||
|
||||
ErrorCode err = userAccountService.logoutService("username",
|
||||
"token");
|
||||
//获取token值
|
||||
String token = UserRequestUtil.getCurrentToken();
|
||||
ErrorCode err = userAccountService.logoutService(username, token);
|
||||
//ErrorCode err = userAccountService.logoutService("username", "token");
|
||||
|
||||
// 注销失败
|
||||
if (err != ErrorCode.ERR_OK) {
|
||||
|
|
|
@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(title = "用户登录请求体")
|
||||
@Schema(title = "用户请求体")
|
||||
public class UserLoginReqDTO {
|
||||
/**
|
||||
* The Username.
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.zjyr.beidouservice.utils;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
* 获取请求头中的token工具类
|
||||
*/
|
||||
public class UserRequestUtil {
|
||||
public static String getCurrentToken() {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes()))
|
||||
.getRequest();
|
||||
return request.getHeader("token");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue