|
|
|
@ -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
|
|
|
|
|
{
|
|
|
|
|