PDF Polish (#2837)

Co-authored-by: William Brockhus <pickeringw@gmail.com>
This commit is contained in:
Joe Milazzo 2024-04-09 17:57:28 -05:00 committed by GitHub
parent 6ed634f5d1
commit 752fda0e93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 103 additions and 106 deletions

View file

@ -37,6 +37,9 @@ namespace API.Controllers;
/// </summary>
public class AccountController : BaseApiController
{
// Hardcoded to avoid localization multiple enumeration: https://github.com/Kareadita/Kavita/issues/2829
private const string BadCredentialsMessage = "Your credentials are not correct";
private readonly UserManager<AppUser> _userManager;
private readonly SignInManager<AppUser> _signInManager;
private readonly ITokenService _tokenService;
@ -204,7 +207,7 @@ public class AccountController : BaseApiController
if (user == null)
{
_logger.LogWarning("Attempted login by {UserName} failed due to unable to find account", loginDto.Username);
return Unauthorized(await _localizationService.Get("en", "bad-credentials"));
return Unauthorized(BadCredentialsMessage);
}
var roles = await _userManager.GetRolesAsync(user);
if (!roles.Contains(PolicyConstants.LoginRole)) return Unauthorized(await _localizationService.Translate(user.Id, "disabled-account"));
@ -225,10 +228,10 @@ public class AccountController : BaseApiController
if (!result.Succeeded)
{
var errorStr = await _localizationService.Translate(user.Id,
result.IsNotAllowed ? "confirm-email" : "bad-credentials");
_logger.LogWarning("{UserName} failed to log in at {Time}: {Issue}", user.UserName, user.LastActive,
errorStr);
string errorStr = result.IsNotAllowed
? await _localizationService.Translate(user.Id, "confirm-email")
: BadCredentialsMessage;
_logger.LogWarning("{UserName} failed to log in at {Time}: {Issue}", user.UserName, user.LastActive, errorStr);
return Unauthorized(errorStr);
}
}
@ -858,7 +861,7 @@ public class AccountController : BaseApiController
var user = await _unitOfWork.UserRepository.GetUserByEmailAsync(dto.Email);
if (user == null)
{
return BadRequest(await _localizationService.Get("en", "bad-credentials"));
return BadRequest(BadCredentialsMessage);
}
try
@ -868,7 +871,7 @@ public class AccountController : BaseApiController
if (!result)
{
_logger.LogInformation("Unable to reset password, your email token is not correct: {@Dto}", dto);
return BadRequest(await _localizationService.Translate(user.Id, "bad-credentials"));
return BadRequest(BadCredentialsMessage);
}
var errors = await _accountService.ChangeUserPassword(user, dto.Password);
@ -948,12 +951,12 @@ public class AccountController : BaseApiController
public async Task<ActionResult<UserDto>> ConfirmMigrationEmail(ConfirmMigrationEmailDto dto)
{
var user = await _unitOfWork.UserRepository.GetUserByEmailAsync(dto.Email);
if (user == null) return BadRequest(await _localizationService.Get("en", "bad-credentials"));
if (user == null) return BadRequest(BadCredentialsMessage);
if (!await ConfirmEmailToken(dto.Token, user))
{
_logger.LogInformation("confirm-migration-email email token is invalid");
return BadRequest(await _localizationService.Translate(user.Id, "bad-credentials"));
return BadRequest(BadCredentialsMessage);
}
await _unitOfWork.CommitAsync();

View file

@ -119,7 +119,6 @@ public class UsersController : BaseApiController
existingPreferences.ShareReviews = preferencesDto.ShareReviews;
existingPreferences.PdfTheme = preferencesDto.PdfTheme;
existingPreferences.PdfLayoutMode = preferencesDto.PdfLayoutMode;
existingPreferences.PdfScrollMode = preferencesDto.PdfScrollMode;
existingPreferences.PdfSpreadMode = preferencesDto.PdfSpreadMode;

View file

@ -118,7 +118,8 @@ public class AppUserPreferences
/// <summary>
/// PDF Reader: Layout Mode of the reader
/// </summary>
public PdfLayoutMode PdfLayoutMode { get; set; } = PdfLayoutMode.Multiple;
/// Book mode is too buggy to include
//public PdfLayoutMode PdfLayoutMode { get; set; } = PdfLayoutMode.Multiple;
/// <summary>
/// PDF Reader: Spread Mode of the reader
/// </summary>

View file

@ -1,6 +1,5 @@
{
"confirm-email": "You must confirm your email first",
"bad-credentials": "Your credentials are not correct",
"locked-out": "You've been locked out from too many authorization attempts. Please wait 10 minutes.",
"disabled-account": "Your account is disabled. Contact the server admin.",
"register-user": "Something went wrong when registering user",