using DotBased.AspNet.Authority.Crypto; using DotBased.AspNet.Authority.Models.Validation; using DotBased.AspNet.Authority.Repositories; using DotBased.AspNet.Authority.Validators; using DotBased.Logging; namespace DotBased.AspNet.Authority.Services; public class AuthorityUserManager where TUser : class { public AuthorityUserManager( AuthorityManager manager, IUserRepository userRepository, IPasswordHasher passwordHasher, IEnumerable>? passwordValidators, IEnumerable>? userValidators) { _logger = LogService.RegisterLogger>(); AuthorityManager = manager; UserRepository = userRepository; PasswordHasher = passwordHasher; if (passwordValidators != null) PasswordValidators = passwordValidators; if (userValidators != null) UserValidators = userValidators; } private readonly ILogger _logger; public AuthorityManager AuthorityManager { get; } public IUserRepository UserRepository { get; } public IPasswordHasher PasswordHasher { get; } public IEnumerable> PasswordValidators { get; } = []; public IEnumerable> UserValidators { get; } = []; public async Task ValidatePasswordAsync(TUser user, string password) { List errors = []; foreach (var validator in PasswordValidators) { var validatorResult = await validator.ValidatePasswordAsync(this, user, password); if (!validatorResult.Success) { errors.AddRange(validatorResult.Errors); } } return errors.Count > 0 ? ValidationResult.Failed(errors) : ValidationResult.Ok(); } }