fix gao user invite validate

This commit is contained in:
Timi
2026-08-21 23:51:38 +08:00
parent 2e9225852d
commit fcae2eac09
2 changed files with 13 additions and 5 deletions
@@ -66,6 +66,7 @@ public class GaoUserInviteServiceImplement implements GaoUserInviteService {
private static final long REGISTER_RATE_LIMIT_TTL = Time.M * 10;
private static final int CODE_RATE_LIMIT = 30;
private static final int REGISTER_VALUE_RATE_LIMIT = 10;
private static final String INVALID_INVITE_MESSAGE = "邀请码无效或已过期";
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
@@ -152,9 +153,16 @@ public class GaoUserInviteServiceImplement implements GaoUserInviteService {
public GaoUserInviteValidateResponse validate(String code) {
TimiException.required(code, "not found code");
checkCodeRateLimit(code);
try {
GaoUserInviteCache cache = requireValidInvite(code);
validateInviteTarget(cache);
return new GaoUserInviteValidateResponse(true, cache.getExpireAt());
} catch (TimiException e) {
if (TimiCode.ARG_BAD == e.getCode() && INVALID_INVITE_MESSAGE.equals(e.getMessage())) {
return new GaoUserInviteValidateResponse(false, -1L);
}
throw e;
}
}
@Transactional(TimiServerDBConfig.ROLLBACKER)
@@ -354,7 +362,7 @@ public class GaoUserInviteServiceImplement implements GaoUserInviteService {
}
private TimiException invalidInvite() {
return new TimiException(TimiCode.ARG_BAD, "邀请码无效或已过期");
return new TimiException(TimiCode.ARG_BAD, INVALID_INVITE_MESSAGE);
}
private boolean isCoreAdmin() {
@@ -14,6 +14,6 @@ public class GaoUserInviteValidateResponse {
/// true 为邀请码可用
private boolean valid;
/// 邀请过期时间,毫秒时间戳
/// 邀请过期时间,毫秒时间戳valid 为 false 时为 0
private Long expireAt;
}