diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs index b8a18e65d..f92d72251 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 6b861e8d5..afb897e7d 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -589,13 +589,30 @@ public async Task VerifyPhoneExisting(string phone, string regionCode) public async Task SendVerificationCodeNoLogin(User user) { - var db = _services.GetRequiredService(); + User? record = await ResetVerificationCode(user); - User? record = null; + 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 false; + return null; } if (!string.IsNullOrEmpty(user.Phone)) @@ -610,7 +627,7 @@ record = db.GetUserByEmail(user.Email); if (record == null) { - return false; + return null; } record.VerificationCode = Nanoid.Generate(alphabet: "0123456789", size: 6); @@ -618,14 +635,7 @@ record = db.GetUserByEmail(user.Email); //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()