Fix circular dependency
This commit is contained in:
parent
3b085f6a03
commit
303c175714
|
@ -547,9 +547,6 @@ namespace Emby.Server.Implementations
|
|||
|
||||
serviceCollection.AddSingleton(ServerConfigurationManager);
|
||||
|
||||
serviceCollection.AddSingleton<Func<IReadOnlyCollection<IPasswordResetProvider>>>(() => GetExports<IPasswordResetProvider>());
|
||||
serviceCollection.AddSingleton<Func<IReadOnlyCollection<IAuthenticationProvider>>>(() => GetExports<IAuthenticationProvider>());
|
||||
|
||||
serviceCollection.AddSingleton<ILocalizationManager, LocalizationManager>();
|
||||
|
||||
serviceCollection.AddSingleton<IBlurayExaminer, BdInfoExaminer>();
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.IO;
|
|||
using System.Security.Cryptography;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Data.Entities;
|
||||
using MediaBrowser.Common;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Controller.Authentication;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
|
@ -23,7 +24,7 @@ namespace Jellyfin.Server.Implementations.Users
|
|||
private const string BaseResetFileName = "passwordreset";
|
||||
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IApplicationHost _appHost;
|
||||
|
||||
private readonly string _passwordResetFileBase;
|
||||
private readonly string _passwordResetFileBaseDir;
|
||||
|
@ -33,16 +34,17 @@ namespace Jellyfin.Server.Implementations.Users
|
|||
/// </summary>
|
||||
/// <param name="configurationManager">The configuration manager.</param>
|
||||
/// <param name="jsonSerializer">The JSON serializer.</param>
|
||||
/// <param name="userManager">The user manager.</param>
|
||||
/// <param name="appHost">The application host.</param>
|
||||
public DefaultPasswordResetProvider(
|
||||
IServerConfigurationManager configurationManager,
|
||||
IJsonSerializer jsonSerializer,
|
||||
IUserManager userManager)
|
||||
IApplicationHost appHost)
|
||||
{
|
||||
_passwordResetFileBaseDir = configurationManager.ApplicationPaths.ProgramDataPath;
|
||||
_passwordResetFileBase = Path.Combine(_passwordResetFileBaseDir, BaseResetFileName);
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_userManager = userManager;
|
||||
_appHost = appHost;
|
||||
// TODO: Remove the circular dependency on UserManager
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -54,6 +56,7 @@ namespace Jellyfin.Server.Implementations.Users
|
|||
/// <inheritdoc />
|
||||
public async Task<PinRedeemResult> RedeemPasswordResetPin(string pin)
|
||||
{
|
||||
var userManager = _appHost.Resolve<IUserManager>();
|
||||
var usersReset = new List<string>();
|
||||
foreach (var resetFile in Directory.EnumerateFiles(_passwordResetFileBaseDir, $"{BaseResetFileName}*"))
|
||||
{
|
||||
|
@ -72,10 +75,10 @@ namespace Jellyfin.Server.Implementations.Users
|
|||
pin.Replace("-", string.Empty, StringComparison.Ordinal),
|
||||
StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var resetUser = _userManager.GetUserByName(spr.UserName)
|
||||
var resetUser = userManager.GetUserByName(spr.UserName)
|
||||
?? throw new ResourceNotFoundException($"User with a username of {spr.UserName} not found");
|
||||
|
||||
await _userManager.ChangePassword(resetUser, pin).ConfigureAwait(false);
|
||||
await userManager.ChangePassword(resetUser, pin).ConfigureAwait(false);
|
||||
usersReset.Add(resetUser.Username);
|
||||
File.Delete(resetFile);
|
||||
}
|
||||
|
@ -121,7 +124,6 @@ namespace Jellyfin.Server.Implementations.Users
|
|||
}
|
||||
|
||||
user.EasyPassword = pin;
|
||||
await _userManager.UpdateUserAsync(user).ConfigureAwait(false);
|
||||
|
||||
return new ForgotPasswordResult
|
||||
{
|
||||
|
|
|
@ -54,17 +54,13 @@ namespace Jellyfin.Server.Implementations.Users
|
|||
/// <param name="appHost">The application host.</param>
|
||||
/// <param name="imageProcessor">The image processor.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="passwordResetProviders">A function that returns available password reset providers.</param>
|
||||
/// <param name="authenticationProviders">A function that returns available authentication providers.</param>
|
||||
public UserManager(
|
||||
JellyfinDbProvider dbProvider,
|
||||
ICryptoProvider cryptoProvider,
|
||||
INetworkManager networkManager,
|
||||
IApplicationHost appHost,
|
||||
IImageProcessor imageProcessor,
|
||||
ILogger<UserManager> logger,
|
||||
Func<IReadOnlyCollection<IPasswordResetProvider>> passwordResetProviders,
|
||||
Func<IReadOnlyCollection<IAuthenticationProvider>> authenticationProviders)
|
||||
ILogger<UserManager> logger)
|
||||
{
|
||||
_dbProvider = dbProvider;
|
||||
_cryptoProvider = cryptoProvider;
|
||||
|
@ -73,8 +69,8 @@ namespace Jellyfin.Server.Implementations.Users
|
|||
_imageProcessor = imageProcessor;
|
||||
_logger = logger;
|
||||
|
||||
_passwordResetProviders = passwordResetProviders.Invoke();
|
||||
_authenticationProviders = authenticationProviders.Invoke();
|
||||
_passwordResetProviders = appHost.GetExports<IPasswordResetProvider>();
|
||||
_authenticationProviders = appHost.GetExports<IAuthenticationProvider>();
|
||||
|
||||
_invalidAuthProvider = _authenticationProviders.OfType<InvalidAuthProvider>().First();
|
||||
_defaultAuthenticationProvider = _authenticationProviders.OfType<DefaultAuthenticationProvider>().First();
|
||||
|
@ -537,7 +533,12 @@ namespace Jellyfin.Server.Implementations.Users
|
|||
if (user != null && isInNetwork)
|
||||
{
|
||||
var passwordResetProvider = GetPasswordResetProvider(user);
|
||||
return await passwordResetProvider.StartForgotPasswordProcess(user, isInNetwork).ConfigureAwait(false);
|
||||
var result = await passwordResetProvider
|
||||
.StartForgotPasswordProcess(user, isInNetwork)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
await UpdateUserAsync(user).ConfigureAwait(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
return new ForgotPasswordResult
|
||||
|
|
Loading…
Reference in New Issue
Block a user