Merge pull request #18 from Qtoss-AI/hdongDev
hdong: Add send verify code API with none login and login when reset …
This commit is contained in:
commit
f760f07edd
|
|
@ -13,7 +13,8 @@ public interface IUserService
|
|||
Task<User> GetMyProfile();
|
||||
Task<bool> VerifyUserNameExisting(string userName);
|
||||
Task<bool> VerifyEmailExisting(string email);
|
||||
Task<bool> SendVerificationCodeResetPassword(User user);
|
||||
Task<bool> SendVerificationCodeResetPasswordNoLogin(User user);
|
||||
Task<bool> SendVerificationCodeResetPasswordLogin();
|
||||
Task<bool> ResetUserPassword(User user);
|
||||
Task<bool> ModifyUserEmail(string email);
|
||||
Task<bool> ModifyUserPhone(string phone);
|
||||
|
|
|
|||
|
|
@ -412,7 +412,48 @@ public class UserService : IUserService
|
|||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> SendVerificationCodeResetPassword(User user)
|
||||
public async Task<bool> SendVerificationCodeResetPasswordNoLogin(User user)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
|
||||
User? record = null;
|
||||
|
||||
if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(user.Phone))
|
||||
{
|
||||
record = db.GetUserByPhone(user.Phone);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(user.Email))
|
||||
{
|
||||
record = db.GetUserByEmail(user.Email);
|
||||
}
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
hook.VerificationCodeResetPassword(record);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> SendVerificationCodeResetPasswordLogin()
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
|
||||
|
|
@ -422,23 +463,6 @@ public class UserService : IUserService
|
|||
{
|
||||
record = db.GetUserById(_user.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.Phone))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(user.Email))
|
||||
{
|
||||
record = db.GetUserByEmail(user.Email);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(user.Phone))
|
||||
{
|
||||
record = db.GetUserByPhone(user.Phone);
|
||||
}
|
||||
}
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -108,12 +108,20 @@ public class UserController : ControllerBase
|
|||
{
|
||||
return await _userService.VerifyEmailExisting(email);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("/user/verifycode")]
|
||||
[HttpPost("/user/verifycode-out")]
|
||||
public async Task<bool> SendVerificationCodeResetPassword([FromBody] UserCreationModel user)
|
||||
{
|
||||
return await _userService.SendVerificationCodeResetPassword(user.ToUser());
|
||||
return await _userService.SendVerificationCodeResetPasswordNoLogin(user.ToUser());
|
||||
}
|
||||
|
||||
[HttpPost("/user/verifycode-in")]
|
||||
public async Task<bool> SendVerificationCodeResetPasswordLogined()
|
||||
{
|
||||
return await _userService.SendVerificationCodeResetPasswordLogin();
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("/user/resetpassword")]
|
||||
public async Task<bool> ResetUserPassword([FromBody] UserResetPasswordModel user)
|
||||
|
|
|
|||
Loading…
Reference in a new issue