修复jwt的token解析异常导致错误提示,优化登录日志记录,优化刷新token接口参数
This commit is contained in:
+9
-13
@@ -1,25 +1,21 @@
|
||||
package xtools.app.sys.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
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.RestController;
|
||||
import xtools.app.sys.auth.model.dto.TokenDto;
|
||||
import xtools.app.sys.auth.utils.AuthUtils;
|
||||
import xtools.app.sys.model.dto.req.SysLoginRefreshReq;
|
||||
import xtools.app.sys.model.dto.req.SysLoginReq;
|
||||
import xtools.app.sys.service.SysLoginService;
|
||||
import xtools.boot.api.model.dto.Result;
|
||||
import xtools.boot.cache.redis.base.RedisService;
|
||||
|
||||
/**
|
||||
* <p>Title : SysLoginController</p>
|
||||
@@ -39,8 +35,6 @@ import xtools.boot.cache.redis.base.RedisService;
|
||||
public class SysLoginController {
|
||||
|
||||
private final SysLoginService sysLoginService;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
@Operation(summary = "获取验证码")
|
||||
@GetMapping("captcha/*")
|
||||
@@ -51,21 +45,23 @@ public class SysLoginController {
|
||||
|
||||
@Operation(summary = "密码登录")
|
||||
@PostMapping("passwd")
|
||||
public Result<TokenDto> passwd(HttpServletRequest request, @RequestBody @Valid SysLoginReq req) {
|
||||
public Result<TokenDto> passwd(
|
||||
@RequestBody @Valid SysLoginReq req,
|
||||
HttpServletRequest request
|
||||
) {
|
||||
String uid = AuthUtils.getUid(request);
|
||||
req.setUid(uid);
|
||||
return sysLoginService.passwd(req);
|
||||
}
|
||||
|
||||
@Operation(summary = "刷新令牌")
|
||||
@GetMapping("refresh/{refreshToken}")
|
||||
@PostMapping("refresh")
|
||||
public Result<TokenDto> refresh(
|
||||
@Schema(description = "刷新令牌", example = "refreshToken")
|
||||
@NotNull(message = "不能为空")
|
||||
@PathVariable String refreshToken,
|
||||
@RequestBody @Valid SysLoginRefreshReq req,
|
||||
HttpServletRequest request
|
||||
) {
|
||||
return Result.ok(AuthUtils.refreshToken(refreshToken, AuthUtils.getUid(request)));
|
||||
String uid = AuthUtils.getUid(request);
|
||||
return Result.ok(AuthUtils.refreshToken(req.getRefreshToken(), uid));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package xtools.app.sys.model.dto.req;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>Title : SysLoginRefreshReq</p>
|
||||
* <p>Description : SysLoginRefreshReq</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 1.0.0
|
||||
* @date : 2026/1/31 14:04
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SysLoginRefreshReq implements Serializable {
|
||||
|
||||
/**
|
||||
* 刷新令牌
|
||||
*/
|
||||
@NotEmpty(message = "不能为空")
|
||||
@Schema(description = "刷新令牌", example = "xxxx")
|
||||
private String refreshToken;
|
||||
}
|
||||
+7
-3
@@ -22,10 +22,12 @@ import xtools.app.sys.service.SysUserPasswdRuleService;
|
||||
import xtools.app.sys.service.base.SysUserBaseService;
|
||||
import xtools.app.sys.service.base.SysUserRoleBaseService;
|
||||
import xtools.app.sys.utils.PasswdUtils;
|
||||
import xtools.boot.api.constant.BootCommonConstant;
|
||||
import xtools.boot.api.exection.BizError;
|
||||
import xtools.boot.api.exection.BizWarning;
|
||||
import xtools.boot.api.model.dto.Result;
|
||||
import xtools.boot.cache.redis.base.RedisService;
|
||||
import xtools.boot.core.holder.CommonHolder;
|
||||
import xtools.core.BytesUtils;
|
||||
import xtools.core.StringUtils;
|
||||
import xtools.core.dto.ArithmeticDto;
|
||||
@@ -209,10 +211,12 @@ public class SysLoginServiceImpl implements SysLoginService {
|
||||
passwdError(user.getId(), rule);
|
||||
throw new BizWarning("密码错误");
|
||||
}
|
||||
LoginUserDto loginUserDto = sysLoginConvert.entityToCacheDto(user);
|
||||
loginUserDto.setRoleIds(sysUserRoleBaseService.getUserRole(user.getId()));
|
||||
LoginUserDto loginUser = sysLoginConvert.entityToCacheDto(user);
|
||||
loginUser.setRoleIds(sysUserRoleBaseService.getUserRole(user.getId()));
|
||||
redisService.del(captchaKey);
|
||||
return Result.ok(AuthUtils.createToken(loginUserDto, uid));
|
||||
TokenDto token = AuthUtils.createToken(loginUser, uid);
|
||||
CommonHolder.set(BootCommonConstant.AUTH, loginUser);
|
||||
return Result.ok(token);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user