This commit is contained in:
jack ning
2025-11-22 12:48:58 +08:00
parent 77d9487afe
commit 78352ffd79
3 changed files with 18 additions and 0 deletions

View File

@@ -95,6 +95,16 @@ public class AuthController {
if (!pushService.validateCode(authRequest.getMobile(), authRequest.getCode(), request)) {
return ResponseEntity.ok().body(JsonResult.error(I18Consts.I18N_AUTH_CAPTCHA_VALIDATE_FAILED, -2, false));
}
// 验证用户名和手机号是否为同一个用户
if (StringUtils.hasText(authRequest.getUsername()) && StringUtils.hasText(authRequest.getMobile())) {
Boolean userMatch = userService.existsByUsernameAndMobileAndPlatform(
authRequest.getUsername(),
authRequest.getMobile(),
authRequest.getPlatform());
if (!userMatch) {
return ResponseEntity.ok().body(JsonResult.error("用户名和手机号不匹配,请检查后重新输入", -3, false));
}
}
}
try {

View File

@@ -42,6 +42,8 @@ public interface UserRepository extends JpaRepository<UserEntity, Long>, JpaSpec
Boolean existsByEmailAndPlatformAndDeletedFalse(String email, String platform);
Boolean existsByUsernameAndMobileAndPlatformAndDeletedFalse(String username, String mobile, String platform);
Boolean existsBySuperUserAndDeletedFalse(Boolean superUser);
}

View File

@@ -616,6 +616,12 @@ public class UserService {
return userRepository.existsByEmailAndPlatformAndDeletedFalse(email, platform);
}
// exists by username and mobile
@Cacheable(value = "user:exists", key = "#username + '-' + #mobile + '-' + #platform", unless = "#result == null")
public Boolean existsByUsernameAndMobileAndPlatform(@NonNull String username, @NonNull String mobile, @NonNull String platform) {
return userRepository.existsByUsernameAndMobileAndPlatformAndDeletedFalse(username, mobile, platform);
}
public Boolean existsBySuperUser() {
return userRepository.existsBySuperUserAndDeletedFalse(true);
}