The Free Software Media System - Server Backend & API
Fix circular dependency
Patrick Barron303c175714db
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.csindex 908fe4b302..1ff14bdb5c 100644--- a/Emby.Server.Implementations/ApplicationHost.cs+++ b/Emby.Server.Implementations/ApplicationHost.cs@@ -547,9 +547,6 @@ namespace Emby.Server.ImplementationsserviceCollection.AddSingleton(ServerConfigurationManager);- serviceCollection.AddSingleton<Func<IReadOnlyCollection<IPasswordResetProvider>>>(() => GetExports<IPasswordResetProvider>());- serviceCollection.AddSingleton<Func<IReadOnlyCollection<IAuthenticationProvider>>>(() => GetExports<IAuthenticationProvider>());-serviceCollection.AddSingleton<ILocalizationManager, LocalizationManager>();serviceCollection.AddSingleton<IBlurayExaminer, BdInfoExaminer>();diff --git a/Jellyfin.Server.Implementations/Users/DefaultPasswordResetProvider.cs b/Jellyfin.Server.Implementations/Users/DefaultPasswordResetProvider.csindex cf5a01f083..007c296436 100644--- a/Jellyfin.Server.Implementations/Users/DefaultPasswordResetProvider.cs+++ b/Jellyfin.Server.Implementations/Users/DefaultPasswordResetProvider.cs@@ -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.Usersprivate 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.Userspin.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{diff --git a/Jellyfin.Server.Implementations/Users/UserManager.cs b/Jellyfin.Server.Implementations/Users/UserManager.csindex d4b91f3c53..988b0c430b 100644--- a/Jellyfin.Server.Implementations/Users/UserManager.cs+++ b/Jellyfin.Server.Implementations/Users/UserManager.cs@@ -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.Usersif (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