Add update password API
This commit is contained in:
parent
8cb97af629
commit
b89d88ffb2
|
|
@ -16,4 +16,5 @@ public interface IUserService
|
|||
Task<bool> ResetUserPassword(User user);
|
||||
Task<bool> ModifyUserEmail(string email);
|
||||
Task<bool> ModifyUserPhone(string phone);
|
||||
Task<bool> UpdatePassword(string newPassword, string verificationCode);
|
||||
}
|
||||
|
|
@ -83,6 +83,28 @@ public class UserService : IUserService
|
|||
return record;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdatePassword(string password, string verificationCode)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var record = db.GetUserByUserName(_user.UserName);
|
||||
|
||||
if (record == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (record.VerificationCode != verificationCode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var salt = Guid.NewGuid().ToString("N");
|
||||
record.Password = Utilities.HashTextMd5($"{password}{salt}");
|
||||
|
||||
db.UpdateUserPassword(record.Id, password);
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<Token?> GetToken(string authorization)
|
||||
{
|
||||
var base64 = Encoding.UTF8.GetString(Convert.FromBase64String(authorization));
|
||||
|
|
|
|||
|
|
@ -121,6 +121,16 @@ public class UserController : ControllerBase
|
|||
return await _userService.ResetUserPassword(user.ToUser());
|
||||
}
|
||||
|
||||
[HttpPost("/user/updatepassword")]
|
||||
public async Task<bool> UpdatePassword([FromBody] User user)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(user.Password) || string.IsNullOrWhiteSpace(user.VerificationCode))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return await _userService.UpdatePassword(user.Password, user.VerificationCode);
|
||||
}
|
||||
|
||||
[HttpPost("/user/email/modify")]
|
||||
public async Task<bool> ModifyUserEmail([FromQuery] string email)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue