mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-31 04:04:19 -04:00
* Implemented the ability to disable authentication on a server instance. Admins will require authentication, but non-admin accounts can be setup without any password requirements. * WIP for new login page. * Reworked code to handle disabled auth better. First time user flow is moved into the user login component. * Removed debug code * Removed home component, shakeout testing is complete. * remove a file accidently committed * Fixed a code smell from last PR * Code smells
54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using API.Entities;
|
|
using API.Errors;
|
|
using API.Interfaces.Services;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace API.Services
|
|
{
|
|
public class AccountService : IAccountService
|
|
{
|
|
private readonly UserManager<AppUser> _userManager;
|
|
private readonly ILogger<AccountService> _logger;
|
|
public const string DefaultPassword = "[k.2@RZ!mxCQkJzE";
|
|
|
|
public AccountService(UserManager<AppUser> userManager, ILogger<AccountService> logger)
|
|
{
|
|
_userManager = userManager;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task<IEnumerable<ApiException>> ChangeUserPassword(AppUser user, string newPassword)
|
|
{
|
|
foreach (var validator in _userManager.PasswordValidators)
|
|
{
|
|
var validationResult = await validator.ValidateAsync(_userManager, user, newPassword);
|
|
if (!validationResult.Succeeded)
|
|
{
|
|
return validationResult.Errors.Select(e => new ApiException(400, e.Code, e.Description));
|
|
}
|
|
}
|
|
|
|
var result = await _userManager.RemovePasswordAsync(user);
|
|
if (!result.Succeeded)
|
|
{
|
|
_logger.LogError("Could not update password");
|
|
return result.Errors.Select(e => new ApiException(400, e.Code, e.Description));
|
|
}
|
|
|
|
|
|
result = await _userManager.AddPasswordAsync(user, newPassword);
|
|
if (!result.Succeeded)
|
|
{
|
|
_logger.LogError("Could not update password");
|
|
return result.Errors.Select(e => new ApiException(400, e.Code, e.Description));
|
|
}
|
|
|
|
return new List<ApiException>();
|
|
}
|
|
}
|
|
}
|