Merge pull request #68 from Qtoss-AI/hdongDev
hdong: split event to update verification code and send.
This commit is contained in:
commit
1fc7bc33d3
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -589,15 +589,32 @@ public class UserService : IUserService
|
|||
|
||||
public async Task<bool> SendVerificationCodeNoLogin(User user)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
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<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 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<IAuthenticationHook>();
|
||||
foreach (var hook in hooks)
|
||||
{
|
||||
await hook.SendVerificationCode(record);
|
||||
}
|
||||
|
||||
return true;
|
||||
return record;
|
||||
}
|
||||
|
||||
public async Task<bool> SendVerificationCodeLogin()
|
||||
|
|
|
|||
Loading…
Reference in a new issue