Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public interface IUserService
Task<bool> VerifyUserNameExisting(string userName);
Task<bool> VerifyEmailExisting(string email);
Task<bool> VerifyPhoneExisting(string phone, string regionCode);
Task<User> ResetVerificationCode(User user);
Task<bool> SendVerificationCodeNoLogin(User user);
Task<bool> SendVerificationCodeLogin();
Task<bool> SetUserPassword(User user);
Expand Down
34 changes: 22 additions & 12 deletions src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,13 +589,30 @@ public async Task<bool> VerifyPhoneExisting(string phone, string regionCode)

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

User? record = null;
if (record == null)
{
return false;
}

//send code to user Email.
var hooks = _services.GetServices<IAuthenticationHook>();
foreach (var hook in hooks)
{
await hook.SendVerificationCode(record);
}

return true;
}

public async Task<User> ResetVerificationCode(User user)
{
var db = _services.GetRequiredService<IBotSharpRepository>();
User record = null;
if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone))
{
return false;
return null;
}

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

if (record == null)
{
return false;
return null;
}

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

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

//send code to user Email.
var hooks = _services.GetServices<IAuthenticationHook>();
foreach (var hook in hooks)
{
await hook.SendVerificationCode(record);
}

return true;
return record;
}

public async Task<bool> SendVerificationCodeLogin()
Expand Down