fix UserType enum mapping and implement unified API response

- Fix UserType enum mapping issue by adding fromValue method and custom type handler
- Create unified API response structure with ErrorCode constants
- Update AuthController to use standardized response format with proper error codes
- Add verification code authentication system replacing password-based auth
- Improve Swagger documentation with detailed API annotations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yahaozhang
2025-07-20 14:45:43 +08:00
parent 479f671edc
commit 36c5d7f760
16 changed files with 618 additions and 72 deletions

54
README.md Normal file
View File

@@ -0,0 +1,54 @@
# 验证码认证实现说明
本项目实现了基于验证码的用户认证机制,不再使用密码进行登录和注册。
## 主要变更
1. **验证码请求和验证DTO**
- `VerificationCodeRequest`: 请求发送验证码的DTO
- `VerifyCodeRequest`: 验证验证码的DTO
- 修改了`LoginRequest``RegisterRequest`,移除密码字段,改为使用验证码
2. **认证控制器**
- 新增了`/api/auth/send-code`接口用于发送验证码
- 修改了登录和注册接口以使用验证码认证
3. **用户服务**
- 实现了验证码生成、存储和验证逻辑
- 在开发模式下,验证码会在控制台输出
- 支持使用万能验证码(默认为"123456")用于测试
4. **配置**
-`application.yml`中添加了验证码相关的配置
- 支持配置验证码过期时间、万能验证码和开发模式
5. **安全配置**
- 更新了`SecurityConfig`以支持跨域请求
- 优化了安全配置结构
## 使用说明
1. 用户注册/登录流程:
- 用户输入邮箱或手机号,请求发送验证码
- 系统生成验证码,在开发模式下控制台会输出验证码
- 用户输入收到的验证码进行注册或登录
2. 万能验证码:
- 在开发或测试环境中,可以使用配置的万能验证码(默认为"123456"
- 无需等待验证码发送,直接使用万能验证码即可
3. 配置说明:
```yaml
app:
verification-code:
expiration: 300 # 验证码有效期(秒)
master-code: "123456" # 万能验证码
development-mode: true # 开发模式(控制台输出验证码)
```
## 注意事项
1. 实际生产环境中应使用Redis等缓存存储验证码而非内存存储
2. 需实现真实的短信和邮件发送服务来发送验证码
3. 生产环境应禁用万能验证码和开发模式
4. 当前实现为开发测试版本,注重功能实现,生产环境应加强安全性