feat: add renew password
This commit is contained in:
parent
a27549092b
commit
592e8a1b42
@ -7,6 +7,7 @@ using Mirea.Api.Dto.Common;
|
||||
using Mirea.Api.Dto.Requests;
|
||||
using Mirea.Api.Dto.Responses;
|
||||
using Mirea.Api.Endpoint.Common.Attributes;
|
||||
using Mirea.Api.Endpoint.Common.Exceptions;
|
||||
using Mirea.Api.Endpoint.Common.Services;
|
||||
using Mirea.Api.Endpoint.Common.Settings;
|
||||
using Mirea.Api.Security.Common.Dto.Requests;
|
||||
@ -165,4 +166,29 @@ public class AuthController(IOptionsSnapshot<Admin> user, AuthService auth, Pass
|
||||
[Authorize]
|
||||
[CacheMaxAge(0, 0, 1)]
|
||||
public ActionResult<AuthRoles> GetRole() => Ok(AuthRoles.Admin);
|
||||
|
||||
[HttpPost("RenewPassword")]
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
[Localhost]
|
||||
[BadRequestResponse]
|
||||
public ActionResult<string> RenewPassword([FromBody] string? password = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(password))
|
||||
password = string.Empty;
|
||||
else if (!PasswordHashService.HasPasswordInPolicySecurity(password))
|
||||
throw new ControllerArgumentException("The password must be at least 8 characters long and contain at least one uppercase letter and one special character.");
|
||||
|
||||
while (!PasswordHashService.HasPasswordInPolicySecurity(password))
|
||||
password = GeneratorKey.GenerateAlphaNumeric(16, includes: "!@#%^");
|
||||
|
||||
var (salt, hash) = passwordService.HashPassword(password);
|
||||
|
||||
var admin = user.Value;
|
||||
|
||||
admin.Salt = salt;
|
||||
admin.PasswordHash = hash;
|
||||
admin.SaveSetting();
|
||||
|
||||
return Ok(password);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user