feat(auth): 注册登录支持手机号/邮箱任选其一,解除强绑定限制#104
Open
GaiYa0 wants to merge 1 commit into
Open
Conversation
解决原有设计中手机号和邮箱必须同时提供导致注册失败的问题, 使注册/登录逻辑符合主流互联网产品规范(手机号或邮箱任选其一即可)。 主要改动: - Proto: 移除 LoginRequest 的 buf.validate 强制注解,允许可选字段 - API 层: Register/Login 方法添加"至少一个身份标识"前置校验 + 格式校验 - Service 层: accountservice.Create 添加前置校验,Bind 添加绑定前唯一性检查 - Adapter 层: 新增 Bind/Unbind 方法包装 gRPC 调用,实现 BindUserVoucher/UnbindUserVoucher - JWT: Claims 新增 AccountId 字段,登录时携带 accountId - DB: 新增迁移脚本,account 表添加 Generated Column + 条件唯一索引 - 修复: ClearColumn 中 nil → 空字符串,避免 NOT NULL 约束报错 Co-authored-by: Cursor <cursoragent@cursor.com>
Author
|
针对的问题是issue里v0.1.0待优化的部分:用户注册相关逻辑中,在proto中定义的参数校验要求同时传手机号+邮箱,否则会报错导致注册失败。在产品逻辑上,手机号和邮箱只需要提供一个是最为常见的逻辑,所以注册、登陆等相关逻辑中,应该允许只传手机号或邮箱,然后再对手机号或邮箱进行格式校验 在user表中,手机号和邮箱应一同设置唯一索引,或是不设置唯一索引,由代码逻辑进行判断;否则无法适配只使用手机号或是邮箱注册的逻辑 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
解决原有设计中手机号和邮箱必须同时提供导致注册失败的问题,使注册/登录逻辑符合主流互联网产品设计规范。
核心变更
LoginRequest的buf.validate强制注解,RegisterRequest.password的min_len统一为 8Register/Login添加"至少提供手机号或邮箱之一"的前置校验,以及独立的格式校验(isValidMobile/isValidEmail)accountservice.Create添加前置参数校验;Bind方法添加绑定前唯一性检查,防止手机号/邮箱被多账户绑定baseadapter.Bind/Unbind方法;实现BindUserVoucher/UnbindUserVoucher(消除panic("implement me"))AccountId字段 +NewWithAccount构造函数 +GetAccountId辅助方法sql/20260527000001_v0_3_0_auth_upgrade.sql,为account表添加 Generated Column(mobile_unique/email_unique)+ 条件唯一索引accountrepo.ClearColumn传nil给NOT NULL列 → 改为空字符串""改动文件
backend/shortVideoApiService/api/svapi/user.protobackend/shortVideoApiService/internal/applications/userapp/application.gobackend/shortVideoApiService/internal/applications/userapp/validation.gobackend/shortVideoApiService/internal/infrastructure/adapter/baseadapter/account.gobackend/shortVideoApiService/internal/infrastructure/utils/claims/claims.gobackend/shortVideoApiService/go.modbackend/baseService/internal/domain/service/accountservice/service.gobackend/baseService/internal/infrastructure/dal/models/account.gen.gobackend/baseService/internal/infrastructure/repositories/accountrepo/repository.gobackend/baseService/go.modsql/20260527000001_v0_3_0_auth_upgrade.sqlTest Plan
Made with Cursor