aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Library/UserManager.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-12-16 00:01:57 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-12-16 00:01:57 -0500
commit3c48def0d76417572193cd306846f1516e0e9038 (patch)
tree8570bb756e024eaca9f2d5b8008e43279aa9fb23 /MediaBrowser.Server.Implementations/Library/UserManager.cs
parent7f7d2f85e324bc9e2c6b170c89af0541601e8cad (diff)
sync updates
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/UserManager.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Library/UserManager.cs69
1 files changed, 62 insertions, 7 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs
index ed45e890b..791cae553 100644
--- a/MediaBrowser.Server.Implementations/Library/UserManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Common.Events;
+using System.Collections.Concurrent;
+using MediaBrowser.Common.Events;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
@@ -317,7 +318,8 @@ namespace MediaBrowser.Server.Implementations.Library
ConnectLinkType = user.ConnectLinkType,
ConnectUserId = user.ConnectUserId,
ConnectUserName = user.ConnectUserName,
- ServerId = _appHost.SystemId
+ ServerId = _appHost.SystemId,
+ Policy = user.Policy
};
var image = user.GetImageInfo(ImageType.Primary, 0);
@@ -529,6 +531,8 @@ namespace MediaBrowser.Server.Implementations.Library
_logger.ErrorException("Error deleting file {0}", ex, path);
}
+ DeleteUserPolicy(user);
+
// Force this to be lazy loaded again
Users = await LoadUsers().ConfigureAwait(false);
@@ -715,7 +719,7 @@ namespace MediaBrowser.Server.Implementations.Library
var usersReset = new List<string>();
- var valid = !string.IsNullOrWhiteSpace(_lastPin) &&
+ var valid = !string.IsNullOrWhiteSpace(_lastPin) &&
string.Equals(_lastPin, pin, StringComparison.OrdinalIgnoreCase) &&
_lastPasswordPinCreationResult != null &&
_lastPasswordPinCreationResult.ExpirationDate > DateTime.UtcNow;
@@ -769,14 +773,65 @@ namespace MediaBrowser.Server.Implementations.Library
public DateTime ExpirationDate { get; set; }
}
- public UserPolicy GetUserPolicy(string userId)
+ public UserPolicy GetUserPolicy(User user)
+ {
+ var path = GetPolifyFilePath(user);
+
+ try
+ {
+ lock (_policySyncLock)
+ {
+ return (UserPolicy)_xmlSerializer.DeserializeFromFile(typeof(UserPolicy), path);
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error reading policy file: {0}", ex, path);
+
+ return new UserPolicy
+ {
+ EnableSync = !user.ConnectLinkType.HasValue || user.ConnectLinkType.Value != UserLinkType.Guest
+ };
+ }
+ }
+
+ private readonly object _policySyncLock = new object();
+ public async Task UpdateUserPolicy(string userId, UserPolicy userPolicy)
+ {
+ var user = GetUserById(userId);
+ var path = GetPolifyFilePath(user);
+
+ lock (_policySyncLock)
+ {
+ _xmlSerializer.SerializeToFile(userPolicy, path);
+ user.Policy = userPolicy;
+ }
+ }
+
+ private void DeleteUserPolicy(User user)
{
- throw new NotImplementedException();
+ var path = GetPolifyFilePath(user);
+
+ try
+ {
+ lock (_policySyncLock)
+ {
+ File.Delete(path);
+ }
+ }
+ catch (IOException)
+ {
+
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error deleting policy file", ex);
+ }
}
- public Task UpdateUserPolicy(string userId, UserPolicy userPolicy)
+ private string GetPolifyFilePath(User user)
{
- throw new NotImplementedException();
+ return Path.Combine(user.ConfigurationDirectoryPath, "policy.xml");
}
}
}