From e17d8525bffc426e99c96b1489076d2bc83a8f39 Mon Sep 17 00:00:00 2001 From: YouWeiDH Date: Wed, 15 Jan 2025 19:13:04 +0800 Subject: [PATCH] hdong: split event to update verification code and send. --- .../Users/IUserService.cs | 1 + .../Users/Services/UserService.cs | 36 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs index b8a18e65..f92d7225 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs @@ -23,6 +23,7 @@ public interface IUserService Task VerifyUserNameExisting(string userName); Task VerifyEmailExisting(string email); Task VerifyPhoneExisting(string phone, string regionCode); + Task ResetVerificationCode(User user); Task SendVerificationCodeNoLogin(User user); Task SendVerificationCodeLogin(); Task SetUserPassword(User user); diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index 6b861e8d..afb897e7 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -589,15 +589,32 @@ public class UserService : IUserService public async Task SendVerificationCodeNoLogin(User user) { - var db = _services.GetRequiredService(); + User? record = await ResetVerificationCode(user); - User? record = null; - - if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone)) + if (record == null) { return false; } + //send code to user Email. + var hooks = _services.GetServices(); + foreach (var hook in hooks) + { + await hook.SendVerificationCode(record); + } + + return true; + } + + public async Task ResetVerificationCode(User user) + { + var db = _services.GetRequiredService(); + User record = null; + if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone)) + { + return null; + } + if (!string.IsNullOrEmpty(user.Phone)) { record = db.GetUserByPhone(user.Phone, regionCode: user.RegionCode); @@ -610,7 +627,7 @@ public class UserService : IUserService if (record == null) { - return false; + return null; } record.VerificationCode = Nanoid.Generate(alphabet: "0123456789", size: 6); @@ -618,14 +635,7 @@ public class UserService : IUserService //update current verification code. db.UpdateUserVerificationCode(record.Id, record.VerificationCode); - //send code to user Email. - var hooks = _services.GetServices(); - foreach (var hook in hooks) - { - await hook.SendVerificationCode(record); - } - - return true; + return record; } public async Task SendVerificationCodeLogin()