diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-10-17 00:52:41 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-10-17 00:52:41 -0400 |
| commit | 4f207c43dd912b710345e083adfb6ad45c849b1d (patch) | |
| tree | 56d9e71f10ba8b5f67fee39b846f6ebf2123f6a3 /MediaBrowser.Server.Implementations | |
| parent | 6ca771cc7906ae6524f737ae9bf0bc1b916efb40 (diff) | |
update connect methods
Diffstat (limited to 'MediaBrowser.Server.Implementations')
4 files changed, 54 insertions, 7 deletions
diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index e3d4b600c..f1a9601cb 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -1,4 +1,6 @@ -using MediaBrowser.Common.Configuration; +using System.Security.Cryptography; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; @@ -825,5 +827,24 @@ namespace MediaBrowser.Server.Implementations.Connect _logger.Debug("Connect returned a 404 when removing a user auth link. Handling it."); } } + + public async Task Authenticate(string username, string passwordMd5) + { + var request = new HttpRequestOptions + { + Url = GetConnectUrl("user/authenticate") + }; + + request.SetPostData(new Dictionary<string, string> + { + {"userName",username}, + {"password",passwordMd5} + }); + + // No need to examine the response + using (var stream = (await _httpClient.SendAsync(request, "POST").ConfigureAwait(false)).Content) + { + } + } } } diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index 163ad943e..1b3f64984 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -147,7 +147,12 @@ namespace MediaBrowser.Server.Implementations.Library Users = await LoadUsers().ConfigureAwait(false); } - public async Task<bool> AuthenticateUser(string username, string passwordSha1, string remoteEndPoint) + public Task<bool> AuthenticateUser(string username, string passwordSha1, string remoteEndPoint) + { + return AuthenticateUser(username, passwordSha1, null, remoteEndPoint); + } + + public async Task<bool> AuthenticateUser(string username, string passwordSha1, string passwordMd5, string remoteEndPoint) { if (string.IsNullOrWhiteSpace(username)) { @@ -161,11 +166,31 @@ namespace MediaBrowser.Server.Implementations.Library throw new AuthenticationException(string.Format("The {0} account is currently disabled. Please consult with your administrator.", user.Name)); } - var success = string.Equals(GetPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); + var success = false; - if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword) + // Authenticate using local credentials if not a guest + if (!user.ConnectLinkType.HasValue || user.ConnectLinkType.Value != UserLinkType.Guest) { - success = string.Equals(GetLocalPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); + success = string.Equals(GetPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); + + if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword) + { + success = string.Equals(GetLocalPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); + } + } + + // Maybe user accidently entered connect credentials. let's be flexible + if (!success && user.ConnectLinkType.HasValue && !string.IsNullOrWhiteSpace(passwordMd5)) + { + try + { + await _connectFactory().Authenticate(user.ConnectUserName, passwordMd5).ConfigureAwait(false); + success = true; + } + catch + { + + } } // Update LastActivityDate and LastLoginDate, then save diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index 07faaf884..78ccba96e 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -1245,5 +1245,6 @@ "HeaderSchedule": "Schedule", "OptionEveryday": "Every day", "OptionWeekdays": "Weekdays", - "OptionWeekends": "Weekends" + "OptionWeekends": "Weekends", + "MessageProfileInfoSynced": "User profile information synced with Media Browser Connect." } diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index 9f77f5294..cf204a5ba 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -1252,7 +1252,7 @@ namespace MediaBrowser.Server.Implementations.Session && !(user != null && user.ConnectLinkType.HasValue && user.ConnectLinkType.Value == UserLinkType.Guest); var result = allowWithoutPassword || - await _userManager.AuthenticateUser(request.Username, request.Password, request.RemoteEndPoint).ConfigureAwait(false); + await _userManager.AuthenticateUser(request.Username, request.PasswordSha1, request.PasswordMd5, request.RemoteEndPoint).ConfigureAwait(false); if (!result) { |
