feat(auth):从JWT令牌中提取注册时间

- 在token工具函数中新增getRegisterTimeFromToken方法
- 修改客户端账户注册逻辑,将创建时间写入JWT令牌- 更新前后端代码以正确传递和解析registerTime字段
- 调整API调用逻辑,优先从令牌中获取注册时间
- 清理部分冗余代码和注释
This commit is contained in:
2025-11-18 09:45:22 +08:00
parent d29d4d69da
commit bff057c99b
7 changed files with 40 additions and 38 deletions

View File

@@ -195,6 +195,7 @@ public class ClientAccountController extends BaseController {
.claim("accountId", account.getId())
.claim("username", username)
.claim("clientId", clientId)
.claim("registerTime", account.getCreateTime())
.signWith(SignatureAlgorithm.RS256, jwtRsaKeyService.getPrivateKey())
.compact();
@@ -274,46 +275,38 @@ public class ClientAccountController extends BaseController {
* 新账号注册赠送3天VIP试用期
*/
@PostMapping("/register")
public AjaxResult register(@RequestBody Map<String, String> registerData) {
String username = registerData.get("username");
String password = registerData.get("password");
String deviceId = registerData.get("deviceId");
ClientAccount clientAccount = new ClientAccount();
clientAccount.setUsername(username);
clientAccount.setAccountName(username);
clientAccount.setCreateBy("system");
clientAccount.setStatus("0");
clientAccount.setPermissions("{\"amazon\":true,\"rakuten\":true,\"zebra\":true}");
clientAccount.setPassword(passwordEncoder.encode(password));
clientAccount.setAccountType("trial");
clientAccount.setDeviceLimit(1);
clientAccount.setExpireTime(new Date(System.currentTimeMillis() + 3 * 24L * 60 * 60 * 1000));
public AjaxResult register(@RequestBody Map<String, String> data) {
String username = data.get("username");
ClientAccount account = new ClientAccount();
account.setUsername(username);
account.setAccountName(username);
account.setCreateBy("system");
account.setCreateTime(new Date());
account.setStatus("0");
account.setPermissions("{\"amazon\":true,\"rakuten\":true,\"zebra\":true}");
account.setPassword(passwordEncoder.encode(data.get("password")));
account.setAccountType("trial");
account.setDeviceLimit(1);
account.setExpireTime(new Date(System.currentTimeMillis() + 3 * 24L * 60 * 60 * 1000));
int result = clientAccountService.insertClientAccount(clientAccount);
if (result <= 0) {
return AjaxResult.error("注册失败");
}
if (clientAccountService.insertClientAccount(account) <= 0) return AjaxResult.error("注册失败");
account = clientAccountService.selectClientAccountByUsername(username);
String token = Jwts.builder()
.setHeaderParam("kid", jwtRsaKeyService.getKeyId())
.setSubject(clientAccount.getUsername())
.setSubject(username)
.setIssuedAt(new Date())
.setExpiration(new Date(System.currentTimeMillis() + JWT_EXPIRATION))
.claim("accountId", clientAccount.getId())
.claim("accountId", account.getId())
.claim("username", username)
.claim("clientId", deviceId)
.claim("clientId", data.get("deviceId"))
.claim("registerTime", account.getCreateTime())
.signWith(SignatureAlgorithm.RS256, jwtRsaKeyService.getPrivateKey())
.compact();
return AjaxResult.success(Map.of(
"token", token,
"permissions", clientAccount.getPermissions(),
"accountName", clientAccount.getAccountName(),
"expireTime", clientAccount.getExpireTime(),
"accountType", clientAccount.getAccountType(),
"registerTime", clientAccount.getCreateTime()
));
return AjaxResult.success(Map.of("token", token, "permissions", account.getPermissions(),
"accountName", account.getAccountName(), "expireTime", account.getExpireTime(),
"accountType", account.getAccountType(), "registerTime", account.getCreateTime()));
}
/**

View File

@@ -42,7 +42,6 @@ public class MarkController {
return AjaxResult.success("获取成功", token);
}
// Token 不存在或不可用,重新注册新账号
token = markService.reg();
return AjaxResult.success("注册成功", token);