HaniBlindBox/.kiro/specs/user-auth-migration/tasks.md
2026-01-02 17:17:30 +08:00

191 lines
7.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Implementation Plan: 用户认证系统迁移
## Overview
本任务列表将PHP用户认证系统迁移到.NET 8按照接口优先级逐个迁移每完成一个接口都需要更新API接口文档标记迁移状态。
## Tasks
- [x] 1. 基础设施准备
- [x] 1.1 创建认证相关的DTO和Request/Response模型
- 在HoneyBox.Model/Models目录下创建Auth相关的请求响应模型
- 包括WechatLoginRequest、MobileLoginRequest、ApiResponse等
- _Requirements: 1.1-1.8, 2.1-2.7_
- [x] 1.2 创建服务接口定义
- 在HoneyBox.Core/Interfaces目录下创建IAuthService、IJwtService、IWechatService、IUserService、IIpLocationService接口
- _Requirements: 1.1-1.8, 2.1-2.7, 3.1-3.6_
- [x] 1.3 配置JWT认证中间件
- 在Program.cs中配置JWT Bearer认证
- 添加JwtSettings配置类
- _Requirements: 3.1-3.6_
- [x] 1.4 配置Redis服务
- 添加StackExchange.Redis依赖
- 配置Redis连接和服务注入
- _Requirements: 1.6, 2.1, 2.2, 2.6_
- [ ] 2. JWT服务实现
- [x] 2.1 实现JwtService
- 实现Token生成、验证、刷新功能
- 实现从Token中提取用户ID
- _Requirements: 3.1-3.5_
- [x] 2.2 编写JwtService单元测试
- 测试Token生成和验证
- **Property 3: 登录成功Token生成**
- **Validates: Requirements 3.1, 3.2**
- [x] 2.3 编写Token验证属性测试
- **Property 7: Token验证与授权**
- **Validates: Requirements 3.3, 3.4**
- [-] 3. 用户服务实现
- [x] 3.1 实现UserService基础功能
- 实现用户查找ByOpenId、ByUnionId、ByMobile
- 实现用户创建
- 实现UID生成策略
- _Requirements: 1.2, 1.3, 2.3_
- [x] 3.2 实现用户信息获取和更新
- 实现GetUserInfoAsync
- 实现UpdateUserAsync
- 实现VIP等级计算
- _Requirements: 4.1-4.5_
- [x] 3.3 编写UserService属性测试
- **Property 2: 新用户创建完整性**
- **Property 9: 用户信息完整性**
- **Property 10: 昵称更新验证**
- **Property 11: VIP等级计算**
- **Validates: Requirements 1.3, 2.3, 4.1, 4.2, 4.4, 4.5**
- [x] 4. 微信服务实现
- [x] 4.1 实现WechatService
- 实现GetOpenIdAsync调用微信API获取openid/unionid
- 实现GetMobileAsync获取微信授权手机号
- _Requirements: 1.1, 5.1_
- [x] 4.2 编写WechatService单元测试
- Mock微信API测试
- _Requirements: 1.1, 1.7_
- [ ] 5. IP地理位置服务实现
- [x] 5.1 实现IpLocationService
- 调用高德地图API解析IP地址
- 返回省份、城市、区域编码
- _Requirements: 6.2_
- [x] 6. 认证服务实现
- [x] 6.1 实现AuthService - 微信登录
- 实现WechatMiniProgramLoginAsync
- 包含防抖机制、用户查找/创建、Token生成
- _Requirements: 1.1-1.8_
- [x] 6.2 实现AuthService - 手机号登录
- 实现MobileLoginAsync
- 包含验证码验证、用户查找/创建、Token生成
- _Requirements: 2.1-2.7_
- [x] 6.3 实现AuthService - 手机号绑定
- 实现BindMobileAsync和WechatBindMobileAsync
- 包含账户合并逻辑
- _Requirements: 5.1-5.5_
- [x] 6.4 实现AuthService - 登录记录
- 实现RecordLoginAsync
- 记录登录日志、更新UserAccount
- _Requirements: 6.1, 6.3, 6.4_
- [x] 6.5 实现AuthService - 账号注销
- 实现LogOffAsync
- _Requirements: 7.1-7.3_
- [x] 6.6 编写AuthService属性测试
- **Property 1: 微信登录用户查找优先级**
- **Property 4: 登录防抖机制**
- **Property 5: 推荐关系记录**
- **Property 6: 验证码验证与清理**
- **Property 8: 数据库Token兼容存储**
- **Validates: Requirements 1.2, 1.6, 1.8, 2.1, 2.2, 2.6, 2.7, 3.6**
- [x] 6.7 编写手机号绑定属性测试
- **Property 12: 手机号绑定验证码验证**
- **Property 13: 账户合并正确性**
- **Property 14: 直接绑定手机号**
- **Validates: Requirements 5.1-5.5**
- [x] 6.8 编写登录记录属性测试
- **Property 15: 登录日志记录**
- **Property 16: recordLogin接口返回值**
- **Property 17: 账号注销类型处理**
- **Validates: Requirements 6.1, 6.3, 6.4, 7.1-7.3**
- [x] 7. Checkpoint - 服务层测试验证
- 确保所有服务层单元测试通过
- 确保所有属性测试通过
- 如有问题请询问用户
- [x] 8. 控制器实现 - AuthController
- [x] 8.1 实现微信小程序登录接口 POST /login
- 调用AuthService.WechatMiniProgramLoginAsync
- 更新API接口文档标记迁移状态
- _Requirements: 1.1-1.8_
- [x] 8.2 实现手机号登录接口 POST /mobileLogin
- 调用AuthService.MobileLoginAsync
- 更新API接口文档标记迁移状态
- _Requirements: 2.1-2.7_
- [x] 8.3 实现微信授权绑定手机号接口 POST /login_bind_mobile
- 调用AuthService.WechatBindMobileAsync
- 更新API接口文档标记迁移状态
- _Requirements: 5.1-5.5_
- [x] 8.4 实现验证码绑定手机号接口 POST /bindMobile
- 调用AuthService.BindMobileAsync
- 更新API接口文档标记迁移状态
- _Requirements: 5.1-5.5_
- [x] 8.5 实现登录记录接口 GET|POST /login_record
- 调用AuthService.RecordLoginAsync
- 更新API接口文档标记迁移状态
- _Requirements: 6.1-6.4_
- [x] 9. 控制器实现 - UserController
- [x] 9.1 实现获取用户信息接口 POST /user
- 调用UserService.GetUserInfoAsync
- 更新API接口文档标记迁移状态
- _Requirements: 4.1-4.5_
- [x] 9.2 实现更新用户信息接口 POST /update_userinfo
- 调用UserService.UpdateUserAsync
- 支持Base64头像上传到腾讯云COS
- 更新API接口文档标记迁移状态
- _Requirements: 4.2, 4.3_
- [x] 9.3 实现账号注销接口 POST /user_log_off
- 调用AuthService.LogOffAsync
- 更新API接口文档标记迁移状态
- _Requirements: 7.1-7.3_
- [x] 10. Checkpoint - 控制器测试验证
- 确保所有控制器接口可正常访问
- 使用Postman或HTTP文件测试各接口
- 如有问题请询问用户
- [ ] 11. 集成测试
- [ ] 11.1 编写微信登录集成测试
- 测试完整的微信登录流程
- _Requirements: 1.1-1.8_
- [ ] 11.2 编写手机号登录集成测试
- 测试完整的手机号登录流程
- _Requirements: 2.1-2.7_
- [ ] 11.3 编写用户信息接口集成测试
- 测试用户信息获取和更新流程
- _Requirements: 4.1-4.5_
- [x] 12. 文档更新和最终验证
- [x] 12.1 更新API接口文档
- 确认所有迁移接口都已标记
- 记录新接口地址
- _Requirements: 8.1-8.3_
- [x] 12.2 创建HTTP测试文件
- 在HoneyBox.Api目录下创建auth.http测试文件
- 包含所有认证相关接口的测试请求
- [ ] 13. Final Checkpoint - 完整功能验证
- 确保所有测试通过
- 确保API文档已更新
- 确保与前端兼容性
- 如有问题请询问用户
## Notes
- All tasks are required for comprehensive testing from the start
- Each task references specific requirements for traceability
- Checkpoints ensure incremental validation
- Property tests validate universal correctness properties
- Unit tests validate specific examples and edge cases
- 每迁移完成一个接口都需要在docs/API接口文档.md中标记迁移状态和新接口地址