New Year Bugs (#2513)

This commit is contained in:
Joe Milazzo 2024-01-02 18:53:10 -06:00 committed by GitHub
parent fcacd67d71
commit 5dfcccba7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 230 additions and 142 deletions

View file

@ -318,19 +318,18 @@ public class AccountController : BaseApiController
[HttpPost("reset-api-key")]
public async Task<ActionResult<string>> ResetApiKey()
{
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
if (user == null) throw new KavitaUnauthenticatedUserException();
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername()) ?? throw new KavitaUnauthenticatedUserException();
user.ApiKey = HashUtil.ApiKey();
if (_unitOfWork.HasChanges() && await _unitOfWork.CommitAsync())
{
await _eventHub.SendMessageToAsync(MessageFactory.UserUpdate,
MessageFactory.UserUpdateEvent(user.Id, user.UserName), user.Id);
return Ok(user.ApiKey);
}
await _unitOfWork.RollbackAsync();
return BadRequest(await _localizationService.Translate(User.GetUserId(), "unable-to-reset-key"));
}