mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-03 06:18:28 +01:00
Improvements to UserManager
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Controller.Authentication
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -17,13 +17,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
public class User : BaseItem
|
||||
{
|
||||
public static IUserManager UserManager { get; set; }
|
||||
public static IXmlSerializer XmlSerializer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// From now on all user paths will be Id-based.
|
||||
/// This is for backwards compatibility.
|
||||
/// </summary>
|
||||
public bool UsesIdForConfigurationPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the password.
|
||||
@@ -31,7 +24,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// <value>The password.</value>
|
||||
public string Password { get; set; }
|
||||
public string EasyPassword { get; set; }
|
||||
public string Salt { get; set; }
|
||||
|
||||
// Strictly to remove IgnoreDataMember
|
||||
public override ItemImageInfo[] ImageInfos
|
||||
@@ -148,46 +140,23 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public Task Rename(string newName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(newName))
|
||||
if (string.IsNullOrWhiteSpace(newName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(newName));
|
||||
}
|
||||
|
||||
// If only the casing is changing, leave the file system alone
|
||||
if (!UsesIdForConfigurationPath && !string.Equals(newName, Name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
UsesIdForConfigurationPath = true;
|
||||
|
||||
// Move configuration
|
||||
var newConfigDirectory = GetConfigurationDirectoryPath(newName);
|
||||
var oldConfigurationDirectory = ConfigurationDirectoryPath;
|
||||
|
||||
// Exceptions will be thrown if these paths already exist
|
||||
if (Directory.Exists(newConfigDirectory))
|
||||
{
|
||||
Directory.Delete(newConfigDirectory, true);
|
||||
}
|
||||
|
||||
if (Directory.Exists(oldConfigurationDirectory))
|
||||
{
|
||||
Directory.Move(oldConfigurationDirectory, newConfigDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.CreateDirectory(newConfigDirectory);
|
||||
}
|
||||
throw new ArgumentException("Username can't be empty", nameof(newName));
|
||||
}
|
||||
|
||||
Name = newName;
|
||||
|
||||
return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem))
|
||||
{
|
||||
ReplaceAllMetadata = true,
|
||||
ImageRefreshMode = MetadataRefreshMode.FullRefresh,
|
||||
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
|
||||
ForceSave = true
|
||||
return RefreshMetadata(
|
||||
new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem))
|
||||
{
|
||||
ReplaceAllMetadata = true,
|
||||
ImageRefreshMode = MetadataRefreshMode.FullRefresh,
|
||||
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
|
||||
ForceSave = true
|
||||
|
||||
}, CancellationToken.None);
|
||||
},
|
||||
CancellationToken.None);
|
||||
}
|
||||
|
||||
public override void UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
|
||||
@@ -216,19 +185,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
var parentPath = ConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath;
|
||||
|
||||
// Legacy
|
||||
if (!UsesIdForConfigurationPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(username))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(username));
|
||||
}
|
||||
|
||||
var safeFolderName = FileSystem.GetValidFilename(username);
|
||||
|
||||
return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath, safeFolderName);
|
||||
}
|
||||
|
||||
// TODO: Remove idPath and just use usernamePath for future releases
|
||||
var usernamePath = System.IO.Path.Combine(parentPath, username);
|
||||
var idPath = System.IO.Path.Combine(parentPath, Id.ToString("N", CultureInfo.InvariantCulture));
|
||||
|
||||
@@ -22,6 +22,12 @@ namespace MediaBrowser.Controller.Library
|
||||
/// <value>The users.</value>
|
||||
IEnumerable<User> Users { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user ids.
|
||||
/// </summary>
|
||||
/// <value>The users ids.</value>
|
||||
IEnumerable<Guid> UsersIds { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when [user updated].
|
||||
/// </summary>
|
||||
@@ -92,7 +98,7 @@ namespace MediaBrowser.Controller.Library
|
||||
/// <returns>User.</returns>
|
||||
/// <exception cref="ArgumentNullException">name</exception>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
Task<User> CreateUser(string name);
|
||||
User CreateUser(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the user.
|
||||
@@ -101,7 +107,7 @@ namespace MediaBrowser.Controller.Library
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="ArgumentNullException">user</exception>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
Task DeleteUser(User user);
|
||||
void DeleteUser(User user);
|
||||
|
||||
/// <summary>
|
||||
/// Resets the password.
|
||||
|
||||
Reference in New Issue
Block a user