aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Library/UserManager.cs
diff options
context:
space:
mode:
authorAndrew Rabert <6550543+nvllsvm@users.noreply.github.com>2019-01-22 18:13:47 -0500
committerGitHub <noreply@github.com>2019-01-22 18:13:47 -0500
commit28483bdb54be96ae83e0fded097f534d7e26ba1e (patch)
treee7f4b92326417ebf55eecdf68a01d2c3b9e660d7 /Emby.Server.Implementations/Library/UserManager.cs
parent920c39454c05e979eabe81877269cd4517a03ccf (diff)
parent8106c8393b711a7e1d40487e3caf2b014decbe28 (diff)
Merge pull request #651 from jellyfin/release-10.1.0
Release 10.1.0
Diffstat (limited to 'Emby.Server.Implementations/Library/UserManager.cs')
-rw-r--r--Emby.Server.Implementations/Library/UserManager.cs112
1 files changed, 60 insertions, 52 deletions
diff --git a/Emby.Server.Implementations/Library/UserManager.cs b/Emby.Server.Implementations/Library/UserManager.cs
index 679116fc0..d5bc3d332 100644
--- a/Emby.Server.Implementations/Library/UserManager.cs
+++ b/Emby.Server.Implementations/Library/UserManager.cs
@@ -1,37 +1,37 @@
-using MediaBrowser.Common.Events;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using MediaBrowser.Common.Events;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
+using MediaBrowser.Controller.Authentication;
using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
+using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Providers;
+using MediaBrowser.Controller.Security;
+using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Connect;
+using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Events;
-using Microsoft.Extensions.Logging;
+using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Users;
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using MediaBrowser.Model.Cryptography;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Controller.Authentication;
-using MediaBrowser.Controller.Security;
-using MediaBrowser.Controller.Devices;
-using MediaBrowser.Controller.Session;
-using MediaBrowser.Controller.Plugins;
+using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.Library
{
@@ -44,7 +44,7 @@ namespace Emby.Server.Implementations.Library
/// Gets the users.
/// </summary>
/// <value>The users.</value>
- public IEnumerable<User> Users { get { return _users; } }
+ public IEnumerable<User> Users => _users;
private User[] _users;
@@ -80,9 +80,20 @@ namespace Emby.Server.Implementations.Library
private IAuthenticationProvider[] _authenticationProviders;
private DefaultAuthenticationProvider _defaultAuthenticationProvider;
- public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository, IXmlSerializer xmlSerializer, INetworkManager networkManager, Func<IImageProcessor> imageProcessorFactory, Func<IDtoService> dtoServiceFactory, IServerApplicationHost appHost, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ICryptoProvider cryptographyProvider)
+ public UserManager(
+ ILoggerFactory loggerFactory,
+ IServerConfigurationManager configurationManager,
+ IUserRepository userRepository,
+ IXmlSerializer xmlSerializer,
+ INetworkManager networkManager,
+ Func<IImageProcessor> imageProcessorFactory,
+ Func<IDtoService> dtoServiceFactory,
+ IServerApplicationHost appHost,
+ IJsonSerializer jsonSerializer,
+ IFileSystem fileSystem,
+ ICryptoProvider cryptographyProvider)
{
- _logger = logger;
+ _logger = loggerFactory.CreateLogger(nameof(UserManager));
UserRepository = userRepository;
_xmlSerializer = xmlSerializer;
_networkManager = networkManager;
@@ -158,12 +169,12 @@ namespace Emby.Server.Implementations.Library
/// </summary>
/// <param name="id">The id.</param>
/// <returns>User.</returns>
- /// <exception cref="System.ArgumentNullException"></exception>
+ /// <exception cref="ArgumentNullException"></exception>
public User GetUserById(Guid id)
{
if (id.Equals(Guid.Empty))
{
- throw new ArgumentNullException("id");
+ throw new ArgumentNullException(nameof(id));
}
return Users.FirstOrDefault(u => u.Id == id);
@@ -183,7 +194,7 @@ namespace Emby.Server.Implementations.Library
{
if (string.IsNullOrWhiteSpace(name))
{
- throw new ArgumentNullException("name");
+ throw new ArgumentNullException(nameof(name));
}
return Users.FirstOrDefault(u => string.Equals(u.Name, name, StringComparison.OrdinalIgnoreCase));
@@ -222,7 +233,7 @@ namespace Emby.Server.Implementations.Library
return true;
}
- private bool IsValidUsernameCharacter(char i)
+ private static bool IsValidUsernameCharacter(char i)
{
return !char.Equals(i, '<') && !char.Equals(i, '>');
}
@@ -251,7 +262,7 @@ namespace Emby.Server.Implementations.Library
{
if (string.IsNullOrWhiteSpace(username))
{
- throw new ArgumentNullException("username");
+ throw new ArgumentNullException(nameof(username));
}
var user = Users
@@ -344,7 +355,7 @@ namespace Emby.Server.Implementations.Library
return success ? user : null;
}
- private string GetAuthenticationProviderId(IAuthenticationProvider provider)
+ private static string GetAuthenticationProviderId(IAuthenticationProvider provider)
{
return provider.GetType().FullName;
}
@@ -526,7 +537,7 @@ namespace Emby.Server.Implementations.Library
{
if (user == null)
{
- throw new ArgumentNullException("user");
+ throw new ArgumentNullException(nameof(user));
}
var hasConfiguredPassword = GetAuthenticationProvider(user).HasPassword(user).Result;
@@ -619,18 +630,18 @@ namespace Emby.Server.Implementations.Library
/// <param name="user">The user.</param>
/// <param name="newName">The new name.</param>
/// <returns>Task.</returns>
- /// <exception cref="System.ArgumentNullException">user</exception>
- /// <exception cref="System.ArgumentException"></exception>
+ /// <exception cref="ArgumentNullException">user</exception>
+ /// <exception cref="ArgumentException"></exception>
public async Task RenameUser(User user, string newName)
{
if (user == null)
{
- throw new ArgumentNullException("user");
+ throw new ArgumentNullException(nameof(user));
}
if (string.IsNullOrEmpty(newName))
{
- throw new ArgumentNullException("newName");
+ throw new ArgumentNullException(nameof(newName));
}
if (Users.Any(u => u.Id != user.Id && u.Name.Equals(newName, StringComparison.OrdinalIgnoreCase)))
@@ -652,13 +663,13 @@ namespace Emby.Server.Implementations.Library
/// Updates the user.
/// </summary>
/// <param name="user">The user.</param>
- /// <exception cref="System.ArgumentNullException">user</exception>
- /// <exception cref="System.ArgumentException"></exception>
+ /// <exception cref="ArgumentNullException">user</exception>
+ /// <exception cref="ArgumentException"></exception>
public void UpdateUser(User user)
{
if (user == null)
{
- throw new ArgumentNullException("user");
+ throw new ArgumentNullException(nameof(user));
}
if (user.Id.Equals(Guid.Empty) || !Users.Any(u => u.Id.Equals(user.Id)))
@@ -683,13 +694,13 @@ namespace Emby.Server.Implementations.Library
/// </summary>
/// <param name="name">The name.</param>
/// <returns>User.</returns>
- /// <exception cref="System.ArgumentNullException">name</exception>
- /// <exception cref="System.ArgumentException"></exception>
+ /// <exception cref="ArgumentNullException">name</exception>
+ /// <exception cref="ArgumentException"></exception>
public async Task<User> CreateUser(string name)
{
if (string.IsNullOrWhiteSpace(name))
{
- throw new ArgumentNullException("name");
+ throw new ArgumentNullException(nameof(name));
}
if (!IsValidUsername(name))
@@ -731,13 +742,13 @@ namespace Emby.Server.Implementations.Library
/// </summary>
/// <param name="user">The user.</param>
/// <returns>Task.</returns>
- /// <exception cref="System.ArgumentNullException">user</exception>
- /// <exception cref="System.ArgumentException"></exception>
+ /// <exception cref="ArgumentNullException">user</exception>
+ /// <exception cref="ArgumentException"></exception>
public async Task DeleteUser(User user)
{
if (user == null)
{
- throw new ArgumentNullException("user");
+ throw new ArgumentNullException(nameof(user));
}
var allUsers = Users.ToList();
@@ -804,7 +815,7 @@ namespace Emby.Server.Implementations.Library
{
if (user == null)
{
- throw new ArgumentNullException("user");
+ throw new ArgumentNullException(nameof(user));
}
if (user.ConnectLinkType.HasValue && user.ConnectLinkType.Value == UserLinkType.Guest)
@@ -823,7 +834,7 @@ namespace Emby.Server.Implementations.Library
{
if (user == null)
{
- throw new ArgumentNullException("user");
+ throw new ArgumentNullException(nameof(user));
}
if (newPassword != null)
@@ -833,7 +844,7 @@ namespace Emby.Server.Implementations.Library
if (string.IsNullOrWhiteSpace(newPasswordHash))
{
- throw new ArgumentNullException("newPasswordHash");
+ throw new ArgumentNullException(nameof(newPasswordHash));
}
user.EasyPassword = newPasswordHash;
@@ -848,7 +859,7 @@ namespace Emby.Server.Implementations.Library
/// </summary>
/// <param name="name">The name.</param>
/// <returns>User.</returns>
- private User InstantiateNewUser(string name)
+ private static User InstantiateNewUser(string name)
{
return new User
{
@@ -861,10 +872,7 @@ namespace Emby.Server.Implementations.Library
};
}
- private string PasswordResetFile
- {
- get { return Path.Combine(ConfigurationManager.ApplicationPaths.ProgramDataPath, "passwordreset.txt"); }
- }
+ private string PasswordResetFile => Path.Combine(ConfigurationManager.ApplicationPaths.ProgramDataPath, "passwordreset.txt");
private string _lastPin;
private PasswordPinCreationResult _lastPasswordPinCreationResult;
@@ -888,7 +896,7 @@ namespace Emby.Server.Implementations.Library
text.AppendLine("Use your web browser to visit:");
text.AppendLine(string.Empty);
- text.AppendLine(localAddress + "/web/forgotpasswordpin.html");
+ text.AppendLine(localAddress + "/web/index.html#!/forgotpasswordpin.html");
text.AppendLine(string.Empty);
text.AppendLine("Enter the following pin code:");
text.AppendLine(string.Empty);
@@ -1047,7 +1055,7 @@ namespace Emby.Server.Implementations.Library
}
}
- private UserPolicy GetDefaultPolicy(User user)
+ private static UserPolicy GetDefaultPolicy(User user)
{
return new UserPolicy
{
@@ -1109,12 +1117,12 @@ namespace Emby.Server.Implementations.Library
}
}
- private string GetPolicyFilePath(User user)
+ private static string GetPolicyFilePath(User user)
{
return Path.Combine(user.ConfigurationDirectoryPath, "policy.xml");
}
- private string GetConfigurationFilePath(User user)
+ private static string GetConfigurationFilePath(User user)
{
return Path.Combine(user.ConfigurationDirectoryPath, "config.xml");
}