Skip to content

新增邮箱验证码登录(email_code)支持 - #1488

Merged
Qinyouzeng merged 1 commit into
mainfrom
feature/email-code-login
Oct 12, 2026
Merged

Qinyouzeng merged 1 commit into
mainfrom
feature/email-code-login

Conversation

@MayueCif

Copy link
Copy Markdown
Contributor
  • 新增缓存 key 常量 EMAIL_LOGIN_CODE_PRE、EMAIL_LOGIN_SEND_PRE,并在 CacheKey 中添加 EmailCodeLoginKey、EmailCodeLoginSendKey 生成方法。
  • EmailAgent 支持 SendEmailTypes.Login,使用新增的发送 key 与 value key。
  • 在 CommandHandler 的发送邮件前置校验中将 SendEmailTypes.Login 纳入需存在用户的分支。
  • 新增 LoginByEmailCommand 与 LoginByEmailCommandValidator(校验 Email 与 Code)。
  • 在 CommandHandler 中新增 LoginByEmailAsync:根据邮箱加载用户(含角色与 Staff)、调用 VerifyEmailCodeAsync 校验并移除缓存 key,校验失败抛出 INVALID_EMAIL_CAPTCHA,校验通过返回由 UserDomainService 拼装的用户详情到 command.Result。
  • UserService 新增匿名接口 PostLoginByEmailAsync,发布 LoginByEmailCommand 并返回登录用户模型。
  • 新增 IdentityServer 扩展 grant 验证器 EmailCodeGrantValidator(GrantType="email_code"),从请求读取 Email/Code 调用远端 UserService.LoginByEmailAsync,成功设置 GrantValidationResult 并记录日志,失败返回 InvalidGrant。
  • 在 Program.cs 的 IdentityServer 注册链中加入 .AddExtensionGrantValidator(),启用 email_code 扩展登录方式。

- 新增缓存 key 常量 EMAIL_LOGIN_CODE_PRE、EMAIL_LOGIN_SEND_PRE,并在 CacheKey 中添加 EmailCodeLoginKey、EmailCodeLoginSendKey 生成方法。
- EmailAgent 支持 SendEmailTypes.Login,使用新增的发送 key 与 value key。
- 在 CommandHandler 的发送邮件前置校验中将 SendEmailTypes.Login 纳入需存在用户的分支。
- 新增 LoginByEmailCommand 与 LoginByEmailCommandValidator(校验 Email 与 Code)。
- 在 CommandHandler 中新增 LoginByEmailAsync:根据邮箱加载用户(含角色与 Staff)、调用 VerifyEmailCodeAsync 校验并移除缓存 key,校验失败抛出 INVALID_EMAIL_CAPTCHA,校验通过返回由 UserDomainService 拼装的用户详情到 command.Result。
- UserService 新增匿名接口 PostLoginByEmailAsync,发布 LoginByEmailCommand 并返回登录用户模型。
- 新增 IdentityServer 扩展 grant 验证器 EmailCodeGrantValidator(GrantType="email_code"),从请求读取 Email/Code 调用远端 UserService.LoginByEmailAsync,成功设置 GrantValidationResult 并记录日志,失败返回 InvalidGrant。
- 在 Program.cs 的 IdentityServer 注册链中加入 .AddExtensionGrantValidator<EmailCodeGrantValidator>(),启用 email_code 扩展登录方式。
@sonarqubecloud

Copy link
Copy Markdown

@Qinyouzeng
Qinyouzeng merged commit f03ca8d into main Oct 12, 2026
4 checks passed
@Qinyouzeng
Qinyouzeng deleted the feature/email-code-login branch October 12, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants