feat(auth): 优化注册功能并添加注册异常处理

- 新增 RegistrationException 类用于处理注册相关的异常
- 在全局异常处理器中添加 RegistrationException 的处理逻辑
- 修改用户服务中的注册逻辑,当用户名或邮箱已存在时抛出 RegistrationException
- 更新注册码实体类,将日期时间字段改为字符串类型
- 调整注册码生成和验证逻辑,使用字符串格式的日期时间
This commit is contained in:
ikmkj
2025-08-01 20:06:13 +08:00
parent ef22c0e4b6
commit df80ca6968
6 changed files with 69 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
package com.test.bijihoudaun.common.advice;
import com.test.bijihoudaun.common.exception.BaseException;
import com.test.bijihoudaun.common.exception.RegistrationException;
import com.test.bijihoudaun.common.response.R;
import com.test.bijihoudaun.common.response.ResultCode;
import jakarta.servlet.http.HttpServletRequest;
@@ -33,6 +33,15 @@ public class GlobalExceptionHandler {
return R.fail(e.getResultCode().getCode(), e.getMessage());
}
/**
* 处理注册异常
*/
@ExceptionHandler(RegistrationException.class)
public R<String> handleRegistrationException(RegistrationException e) {
log.warn("Registration attempt failed: {}", e.getMessage());
return R.fail(e.getMessage());
}
/**
* 处理文件大小超出限制异常
*/

View File

@@ -0,0 +1,7 @@
package com.test.bijihoudaun.common.exception;
public class RegistrationException extends RuntimeException {
public RegistrationException(String message) {
super(message);
}
}