feat: 邮箱冲突检测优化 v1.1.1
- 新增邮箱冲突检测:发送验证码前检查邮箱是否已被注册 - 优化用户体验:避免向已注册邮箱发送无用验证码 - 改进错误处理:返回409 Conflict状态码和明确错误信息 - 更新API文档:重新整理文档结构,突出前端开发要点 - 完善测试用例:添加邮箱冲突检测相关测试 - 版本升级:1.1.0 1.1.1 核心修改: - src/core/login_core/login_core.service.ts: 在sendEmailVerification方法中添加邮箱存在性检查 - src/business/auth/controllers/login.controller.ts: 正确处理409冲突状态码 - docs/api/api-documentation.md: 重新整理为精简实用的前端开发文档 - docs/api/openapi.yaml: 更新版本和接口描述 - test-register-fix.ps1: 添加邮箱冲突检测测试用例
This commit is contained in:
@@ -31,7 +31,7 @@ export class AppService {
|
||||
|
||||
return {
|
||||
service: 'Pixel Game Server',
|
||||
version: '1.1.0',
|
||||
version: '1.1.1',
|
||||
status: 'running',
|
||||
timestamp: new Date().toISOString(),
|
||||
uptime: Math.floor((Date.now() - this.startTime) / 1000),
|
||||
|
||||
@@ -389,6 +389,9 @@ export class LoginController {
|
||||
res.status(HttpStatus.OK).json(result);
|
||||
} else if (result.error_code === 'TEST_MODE_ONLY') {
|
||||
res.status(HttpStatus.PARTIAL_CONTENT).json(result); // 206 Partial Content
|
||||
} else if (result.message?.includes('已被注册') || result.message?.includes('已存在')) {
|
||||
// 邮箱已被注册
|
||||
res.status(HttpStatus.CONFLICT).json(result);
|
||||
} else {
|
||||
res.status(HttpStatus.BAD_REQUEST).json(result);
|
||||
}
|
||||
|
||||
@@ -516,6 +516,12 @@ export class LoginCoreService {
|
||||
* @returns 验证码结果
|
||||
*/
|
||||
async sendEmailVerification(email: string, nickname?: string): Promise<VerificationCodeResult> {
|
||||
// 首先检查邮箱是否已经被注册,避免发送无用的验证码
|
||||
const existingUser = await this.usersService.findByEmail(email);
|
||||
if (existingUser) {
|
||||
throw new ConflictException('邮箱已被注册,请使用其他邮箱或直接登录');
|
||||
}
|
||||
|
||||
// 生成验证码
|
||||
const verificationCode = await this.verificationService.generateCode(
|
||||
email,
|
||||
|
||||
@@ -58,8 +58,8 @@ async function bootstrap() {
|
||||
// 配置Swagger文档
|
||||
const config = new DocumentBuilder()
|
||||
.setTitle('Pixel Game Server API')
|
||||
.setDescription('像素游戏服务器API文档 - 包含用户认证、登录注册、验证码登录等功能')
|
||||
.setVersion('1.1.0')
|
||||
.setDescription('像素游戏服务器API文档 - 包含用户认证、登录注册、验证码登录、邮箱冲突检测等功能')
|
||||
.setVersion('1.1.1')
|
||||
.addTag('auth', '用户认证相关接口')
|
||||
.addTag('admin', '管理员后台相关接口')
|
||||
.addBearerAuth(
|
||||
|
||||
Reference in New Issue
Block a user