Skip to content

Commit 1fc7bc3

Browse files
authored
Merge pull request #68 from Qtoss-AI/hdongDev
hdong: split event to update verification code and send.
2 parents 3f7242a + e17d852 commit 1fc7bc3

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public interface IUserService
2323
Task<bool> VerifyUserNameExisting(string userName);
2424
Task<bool> VerifyEmailExisting(string email);
2525
Task<bool> VerifyPhoneExisting(string phone, string regionCode);
26+
Task<User> ResetVerificationCode(User user);
2627
Task<bool> SendVerificationCodeNoLogin(User user);
2728
Task<bool> SendVerificationCodeLogin();
2829
Task<bool> SetUserPassword(User user);

src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -589,13 +589,30 @@ public async Task<bool> VerifyPhoneExisting(string phone, string regionCode)
589589

590590
public async Task<bool> SendVerificationCodeNoLogin(User user)
591591
{
592-
var db = _services.GetRequiredService<IBotSharpRepository>();
592+
User? record = await ResetVerificationCode(user);
593593

594-
User? record = null;
594+
if (record == null)
595+
{
596+
return false;
597+
}
595598

599+
//send code to user Email.
600+
var hooks = _services.GetServices<IAuthenticationHook>();
601+
foreach (var hook in hooks)
602+
{
603+
await hook.SendVerificationCode(record);
604+
}
605+
606+
return true;
607+
}
608+
609+
public async Task<User> ResetVerificationCode(User user)
610+
{
611+
var db = _services.GetRequiredService<IBotSharpRepository>();
612+
User record = null;
596613
if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone))
597614
{
598-
return false;
615+
return null;
599616
}
600617

601618
if (!string.IsNullOrEmpty(user.Phone))
@@ -610,22 +627,15 @@ record = db.GetUserByEmail(user.Email);
610627

611628
if (record == null)
612629
{
613-
return false;
630+
return null;
614631
}
615632

616633
record.VerificationCode = Nanoid.Generate(alphabet: "0123456789", size: 6);
617634

618635
//update current verification code.
619636
db.UpdateUserVerificationCode(record.Id, record.VerificationCode);
620637

621-
//send code to user Email.
622-
var hooks = _services.GetServices<IAuthenticationHook>();
623-
foreach (var hook in hooks)
624-
{
625-
await hook.SendVerificationCode(record);
626-
}
627-
628-
return true;
638+
return record;
629639
}
630640

631641
public async Task<bool> SendVerificationCodeLogin()

0 commit comments

Comments
 (0)