|
|
@ -10,7 +10,6 @@ using MediaBrowser.Controller.Configuration;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
using MediaBrowser.Model.Users;
|
|
|
|
using MediaBrowser.Model.Users;
|
|
|
|
using Microsoft.Win32.SafeHandles;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Emby.Server.Implementations.Library
|
|
|
|
namespace Emby.Server.Implementations.Library
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -37,13 +36,15 @@ namespace Emby.Server.Implementations.Library
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<PinRedeemResult> RedeemPasswordResetPin(string pin)
|
|
|
|
public async Task<PinRedeemResult> RedeemPasswordResetPin(string pin)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
SerializablePasswordReset spr;
|
|
|
|
HashSet<string> usersreset = new HashSet<string>();
|
|
|
|
HashSet<string> usersreset = new HashSet<string>();
|
|
|
|
foreach (var resetfile in Directory.EnumerateFiles(_passwordResetFileBaseDir, $"{_passwordResetFileBaseName}*"))
|
|
|
|
foreach (var resetfile in Directory.EnumerateFiles(_passwordResetFileBaseDir, $"{_passwordResetFileBaseName}*"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var str = File.OpenRead(resetfile))
|
|
|
|
using (var str = File.OpenRead(resetfile))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var spr = await _jsonSerializer.DeserializeFromStreamAsync<SerializablePasswordReset>(str).ConfigureAwait(false);
|
|
|
|
spr = await _jsonSerializer.DeserializeFromStreamAsync<SerializablePasswordReset>(str).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (spr.ExpirationDate < DateTime.Now)
|
|
|
|
if (spr.ExpirationDate < DateTime.Now)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
File.Delete(resetfile);
|
|
|
|
File.Delete(resetfile);
|
|
|
@ -51,14 +52,16 @@ namespace Emby.Server.Implementations.Library
|
|
|
|
else if (spr.Pin == pin)
|
|
|
|
else if (spr.Pin == pin)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var resetUser = _userManager.GetUserByName(spr.UserName);
|
|
|
|
var resetUser = _userManager.GetUserByName(spr.UserName);
|
|
|
|
if (resetUser != null)
|
|
|
|
if (resetUser == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new Exception($"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.Name);
|
|
|
|
usersreset.Add(resetUser.Name);
|
|
|
|
File.Delete(resetfile);
|
|
|
|
File.Delete(resetfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (usersreset.Count < 1)
|
|
|
|
if (usersreset.Count < 1)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -89,10 +92,12 @@ namespace Emby.Server.Implementations.Library
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FileStream fileStream = File.OpenWrite(filePath);
|
|
|
|
using (FileStream fileStream = File.OpenWrite(filePath))
|
|
|
|
|
|
|
|
{
|
|
|
|
_jsonSerializer.SerializeToStream(spr, fileStream);
|
|
|
|
_jsonSerializer.SerializeToStream(spr, fileStream);
|
|
|
|
await fileStream.FlushAsync().ConfigureAwait(false);
|
|
|
|
await fileStream.FlushAsync().ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new Exception($"Error serializing or writing password reset for {user.Name} to location: {filePath}", e);
|
|
|
|
throw new Exception($"Error serializing or writing password reset for {user.Name} to location: {filePath}", e);
|
|
|
|