mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-09 07:10:34 +02:00
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(ServerConfigurationManager);
|
||||||
|
|
||||||
serviceCollection.AddSingleton<Func<IReadOnlyCollection<IPasswordResetProvider>>>(() => GetExports<IPasswordResetProvider>());
|
|
||||||
serviceCollection.AddSingleton<Func<IReadOnlyCollection<IAuthenticationProvider>>>(() => GetExports<IAuthenticationProvider>());
|
|
||||||
|
|
||||||
serviceCollection.AddSingleton<ILocalizationManager, LocalizationManager>();
|
serviceCollection.AddSingleton<ILocalizationManager, LocalizationManager>();
|
||||||
|
|
||||||
serviceCollection.AddSingleton<IBlurayExaminer, BdInfoExaminer>();
|
serviceCollection.AddSingleton<IBlurayExaminer, BdInfoExaminer>();
|
||||||
|
|
|
@ -6,6 +6,7 @@ using System.IO;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Data.Entities;
|
using Jellyfin.Data.Entities;
|
||||||
|
using MediaBrowser.Common;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Controller.Authentication;
|
using MediaBrowser.Controller.Authentication;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
|
@ -23,7 +24,7 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
private const string BaseResetFileName = "passwordreset";
|
private const string BaseResetFileName = "passwordreset";
|
||||||
|
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IUserManager _userManager;
|
private readonly IApplicationHost _appHost;
|
||||||
|
|
||||||
private readonly string _passwordResetFileBase;
|
private readonly string _passwordResetFileBase;
|
||||||
private readonly string _passwordResetFileBaseDir;
|
private readonly string _passwordResetFileBaseDir;
|
||||||
|
@ -33,16 +34,17 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="configurationManager">The configuration manager.</param>
|
/// <param name="configurationManager">The configuration manager.</param>
|
||||||
/// <param name="jsonSerializer">The JSON serializer.</param>
|
/// <param name="jsonSerializer">The JSON serializer.</param>
|
||||||
/// <param name="userManager">The user manager.</param>
|
/// <param name="appHost">The application host.</param>
|
||||||
public DefaultPasswordResetProvider(
|
public DefaultPasswordResetProvider(
|
||||||
IServerConfigurationManager configurationManager,
|
IServerConfigurationManager configurationManager,
|
||||||
IJsonSerializer jsonSerializer,
|
IJsonSerializer jsonSerializer,
|
||||||
IUserManager userManager)
|
IApplicationHost appHost)
|
||||||
{
|
{
|
||||||
_passwordResetFileBaseDir = configurationManager.ApplicationPaths.ProgramDataPath;
|
_passwordResetFileBaseDir = configurationManager.ApplicationPaths.ProgramDataPath;
|
||||||
_passwordResetFileBase = Path.Combine(_passwordResetFileBaseDir, BaseResetFileName);
|
_passwordResetFileBase = Path.Combine(_passwordResetFileBaseDir, BaseResetFileName);
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_userManager = userManager;
|
_appHost = appHost;
|
||||||
|
// TODO: Remove the circular dependency on UserManager
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -54,6 +56,7 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<PinRedeemResult> RedeemPasswordResetPin(string pin)
|
public async Task<PinRedeemResult> RedeemPasswordResetPin(string pin)
|
||||||
{
|
{
|
||||||
|
var userManager = _appHost.Resolve<IUserManager>();
|
||||||
var usersReset = new List<string>();
|
var usersReset = new List<string>();
|
||||||
foreach (var resetFile in Directory.EnumerateFiles(_passwordResetFileBaseDir, $"{BaseResetFileName}*"))
|
foreach (var resetFile in Directory.EnumerateFiles(_passwordResetFileBaseDir, $"{BaseResetFileName}*"))
|
||||||
{
|
{
|
||||||
|
@ -72,10 +75,10 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
pin.Replace("-", string.Empty, StringComparison.Ordinal),
|
pin.Replace("-", string.Empty, StringComparison.Ordinal),
|
||||||
StringComparison.InvariantCultureIgnoreCase))
|
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");
|
?? 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);
|
usersReset.Add(resetUser.Username);
|
||||||
File.Delete(resetFile);
|
File.Delete(resetFile);
|
||||||
}
|
}
|
||||||
|
@ -121,7 +124,6 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
}
|
}
|
||||||
|
|
||||||
user.EasyPassword = pin;
|
user.EasyPassword = pin;
|
||||||
await _userManager.UpdateUserAsync(user).ConfigureAwait(false);
|
|
||||||
|
|
||||||
return new ForgotPasswordResult
|
return new ForgotPasswordResult
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,17 +54,13 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
/// <param name="appHost">The application host.</param>
|
/// <param name="appHost">The application host.</param>
|
||||||
/// <param name="imageProcessor">The image processor.</param>
|
/// <param name="imageProcessor">The image processor.</param>
|
||||||
/// <param name="logger">The logger.</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(
|
public UserManager(
|
||||||
JellyfinDbProvider dbProvider,
|
JellyfinDbProvider dbProvider,
|
||||||
ICryptoProvider cryptoProvider,
|
ICryptoProvider cryptoProvider,
|
||||||
INetworkManager networkManager,
|
INetworkManager networkManager,
|
||||||
IApplicationHost appHost,
|
IApplicationHost appHost,
|
||||||
IImageProcessor imageProcessor,
|
IImageProcessor imageProcessor,
|
||||||
ILogger<UserManager> logger,
|
ILogger<UserManager> logger)
|
||||||
Func<IReadOnlyCollection<IPasswordResetProvider>> passwordResetProviders,
|
|
||||||
Func<IReadOnlyCollection<IAuthenticationProvider>> authenticationProviders)
|
|
||||||
{
|
{
|
||||||
_dbProvider = dbProvider;
|
_dbProvider = dbProvider;
|
||||||
_cryptoProvider = cryptoProvider;
|
_cryptoProvider = cryptoProvider;
|
||||||
|
@ -73,8 +69,8 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
_imageProcessor = imageProcessor;
|
_imageProcessor = imageProcessor;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
_passwordResetProviders = passwordResetProviders.Invoke();
|
_passwordResetProviders = appHost.GetExports<IPasswordResetProvider>();
|
||||||
_authenticationProviders = authenticationProviders.Invoke();
|
_authenticationProviders = appHost.GetExports<IAuthenticationProvider>();
|
||||||
|
|
||||||
_invalidAuthProvider = _authenticationProviders.OfType<InvalidAuthProvider>().First();
|
_invalidAuthProvider = _authenticationProviders.OfType<InvalidAuthProvider>().First();
|
||||||
_defaultAuthenticationProvider = _authenticationProviders.OfType<DefaultAuthenticationProvider>().First();
|
_defaultAuthenticationProvider = _authenticationProviders.OfType<DefaultAuthenticationProvider>().First();
|
||||||
|
@ -537,7 +533,12 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
if (user != null && isInNetwork)
|
if (user != null && isInNetwork)
|
||||||
{
|
{
|
||||||
var passwordResetProvider = GetPasswordResetProvider(user);
|
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
|
return new ForgotPasswordResult
|
||||||
|
|
Loading…
Reference in a new issue