From d8c654f3292e14ba050c3b0f116e41eea6797e57 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 4 Feb 2016 12:50:24 -0500 Subject: stub out pin login service --- MediaBrowser.Api/MediaBrowser.Api.csproj | 1 + MediaBrowser.Api/PinLoginService.cs | 146 +++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 MediaBrowser.Api/PinLoginService.cs (limited to 'MediaBrowser.Api') diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index 7e55446ae7..f711c69e63 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -80,6 +80,7 @@ + diff --git a/MediaBrowser.Api/PinLoginService.cs b/MediaBrowser.Api/PinLoginService.cs new file mode 100644 index 0000000000..81d5903955 --- /dev/null +++ b/MediaBrowser.Api/PinLoginService.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Concurrent; +using System.Globalization; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Controller.Net; +using MediaBrowser.Model.Connect; +using ServiceStack; + +namespace MediaBrowser.Api +{ + [Route("/Auth/Pin", "POST", Summary = "Creates a pin request")] + public class CreatePinRequest : IReturn + { + public string DeviceId { get; set; } + } + + [Route("/Auth/Pin", "GET", Summary = "Gets pin status")] + public class GetPinStatusRequest : IReturn + { + public string DeviceId { get; set; } + public string Pin { get; set; } + } + + [Route("/Auth/Pin/Exchange", "POST", Summary = "Exchanges a pin")] + public class ExchangePinRequest : IReturn + { + public string DeviceId { get; set; } + public string Pin { get; set; } + } + + [Route("/Auth/Pin/Validate", "POST", Summary = "Validates a pin")] + [Authenticated] + public class ValidatePinRequest : IReturnVoid + { + public string Pin { get; set; } + } + + public class PinLoginService : BaseApiService + { + private readonly ConcurrentDictionary _activeRequests = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + + public object Post(CreatePinRequest request) + { + var pin = GetNewPin(5); + var key = GetKey(request.DeviceId, pin); + + var value = new MyPinStatus + { + CreationTimeUtc = DateTime.UtcNow, + IsConfirmed = false, + IsExpired = false, + Pin = pin + }; + + _activeRequests.AddOrUpdate(key, value, (k, v) => value); + + return ToOptimizedResult(new PinCreationResult + { + DeviceId = request.DeviceId, + IsConfirmed = false, + IsExpired = false, + Pin = pin + }); + } + + public object Get(GetPinStatusRequest request) + { + MyPinStatus status; + + if (!_activeRequests.TryGetValue(GetKey(request.DeviceId, request.Pin), out status)) + { + throw new ResourceNotFoundException(); + } + + CheckExpired(status); + + if (status.IsExpired) + { + throw new ResourceNotFoundException(); + } + + return ToOptimizedResult(new PinStatusResult + { + Pin = status.Pin, + IsConfirmed = status.IsConfirmed, + IsExpired = status.IsExpired + }); + } + + public object Post(ExchangePinRequest request) + { + MyPinStatus status; + + if (!_activeRequests.TryGetValue(GetKey(request.DeviceId, request.Pin), out status)) + { + throw new ResourceNotFoundException(); + } + + CheckExpired(status); + + if (status.IsExpired) + { + throw new ResourceNotFoundException(); + } + + return ToOptimizedResult(new PinExchangeResult + { + }); + } + + public void Post(ValidatePinRequest request) + { + } + + private void CheckExpired(MyPinStatus status) + { + if ((DateTime.UtcNow - status.CreationTimeUtc).TotalMinutes > 10) + { + status.IsExpired = true; + } + } + + private string GetNewPin(int length) + { + var pin = string.Empty; + + while (pin.Length < length) + { + var digit = new Random().Next(0, 9); + pin += digit.ToString(CultureInfo.InvariantCulture); + } + + return pin; + } + + private string GetKey(string deviceId, string pin) + { + return deviceId + pin; + } + + public class MyPinStatus : PinStatusResult + { + public DateTime CreationTimeUtc { get; set; } + } + } +} -- cgit v1.2.3 From 7614707dad5aff2847d46105406828f01b3bbd85 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 4 Feb 2016 13:03:40 -0500 Subject: update pin login service --- MediaBrowser.Api/PinLoginService.cs | 92 +++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 18 deletions(-) (limited to 'MediaBrowser.Api') diff --git a/MediaBrowser.Api/PinLoginService.cs b/MediaBrowser.Api/PinLoginService.cs index 81d5903955..8b63de10a5 100644 --- a/MediaBrowser.Api/PinLoginService.cs +++ b/MediaBrowser.Api/PinLoginService.cs @@ -11,20 +11,25 @@ namespace MediaBrowser.Api [Route("/Auth/Pin", "POST", Summary = "Creates a pin request")] public class CreatePinRequest : IReturn { + [ApiMember(Name = "DeviceId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] public string DeviceId { get; set; } } [Route("/Auth/Pin", "GET", Summary = "Gets pin status")] public class GetPinStatusRequest : IReturn { + [ApiMember(Name = "DeviceId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public string DeviceId { get; set; } + [ApiMember(Name = "Pin", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public string Pin { get; set; } } [Route("/Auth/Pin/Exchange", "POST", Summary = "Exchanges a pin")] public class ExchangePinRequest : IReturn { + [ApiMember(Name = "DeviceId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] public string DeviceId { get; set; } + [ApiMember(Name = "Pin", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] public string Pin { get; set; } } @@ -32,6 +37,7 @@ namespace MediaBrowser.Api [Authenticated] public class ValidatePinRequest : IReturnVoid { + [ApiMember(Name = "Pin", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] public string Pin { get; set; } } @@ -41,18 +47,18 @@ namespace MediaBrowser.Api public object Post(CreatePinRequest request) { - var pin = GetNewPin(5); - var key = GetKey(request.DeviceId, pin); + var pin = GetNewPin(); var value = new MyPinStatus { CreationTimeUtc = DateTime.UtcNow, IsConfirmed = false, IsExpired = false, - Pin = pin + Pin = pin, + DeviceId = request.DeviceId }; - _activeRequests.AddOrUpdate(key, value, (k, v) => value); + _activeRequests.AddOrUpdate(pin, value, (k, v) => value); return ToOptimizedResult(new PinCreationResult { @@ -67,17 +73,12 @@ namespace MediaBrowser.Api { MyPinStatus status; - if (!_activeRequests.TryGetValue(GetKey(request.DeviceId, request.Pin), out status)) + if (!_activeRequests.TryGetValue(request.Pin, out status)) { throw new ResourceNotFoundException(); } - CheckExpired(status); - - if (status.IsExpired) - { - throw new ResourceNotFoundException(); - } + EnsureValid(request.DeviceId, status); return ToOptimizedResult(new PinStatusResult { @@ -91,37 +92,78 @@ namespace MediaBrowser.Api { MyPinStatus status; - if (!_activeRequests.TryGetValue(GetKey(request.DeviceId, request.Pin), out status)) + if (!_activeRequests.TryGetValue(request.Pin, out status)) { throw new ResourceNotFoundException(); } - CheckExpired(status); + EnsureValid(request.DeviceId, status); - if (status.IsExpired) + if (!status.IsConfirmed) { throw new ResourceNotFoundException(); } return ToOptimizedResult(new PinExchangeResult { + // TODO: Add access token + UserId = status.UserId }); } public void Post(ValidatePinRequest request) { + MyPinStatus status; + + if (!_activeRequests.TryGetValue(request.Pin, out status)) + { + throw new ResourceNotFoundException(); + } + + EnsureValid(status); + + status.IsConfirmed = true; + status.UserId = AuthorizationContext.GetAuthorizationInfo(Request).UserId; + } + + private void EnsureValid(string requestedDeviceId, MyPinStatus status) + { + if (!string.Equals(requestedDeviceId, status.DeviceId, StringComparison.OrdinalIgnoreCase)) + { + throw new ResourceNotFoundException(); + } + + EnsureValid(status); } - private void CheckExpired(MyPinStatus status) + private void EnsureValid(MyPinStatus status) { if ((DateTime.UtcNow - status.CreationTimeUtc).TotalMinutes > 10) { status.IsExpired = true; } + + if (status.IsExpired) + { + throw new ResourceNotFoundException(); + } } - private string GetNewPin(int length) + private string GetNewPin() { + var pin = GetNewPinInternal(); + + while (IsPinActive(pin)) + { + pin = GetNewPinInternal(); + } + + return pin; + } + + private string GetNewPinInternal() + { + var length = 5; var pin = string.Empty; while (pin.Length < length) @@ -133,14 +175,28 @@ namespace MediaBrowser.Api return pin; } - private string GetKey(string deviceId, string pin) + private bool IsPinActive(string pin) { - return deviceId + pin; + MyPinStatus status; + + if (!_activeRequests.TryGetValue(pin, out status)) + { + return true; + } + + if (status.IsExpired) + { + return true; + } + + return false; } public class MyPinStatus : PinStatusResult { public DateTime CreationTimeUtc { get; set; } + public string DeviceId { get; set; } + public string UserId { get; set; } } } } -- cgit v1.2.3 From 32013f5ae50950f5da2f3113b5fb12a943a83c16 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 5 Feb 2016 11:04:18 -0500 Subject: deprecate merge setting --- MediaBrowser.Api/StartupWizardService.cs | 1 - MediaBrowser.Model/Configuration/ServerConfiguration.cs | 2 -- .../Configuration/ServerConfigurationManager.cs | 15 --------------- 3 files changed, 18 deletions(-) (limited to 'MediaBrowser.Api') diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 6556807c4d..06db1de745 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -68,7 +68,6 @@ namespace MediaBrowser.Api _config.Configuration.EnableLocalizedGuids = true; _config.Configuration.EnableCustomPathSubFolders = true; _config.Configuration.EnableDateLastRefresh = true; - _config.Configuration.MergeMetadataAndImagesByName = true; _config.SaveConfiguration(); } diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 0b472ec223..3cb543e5d5 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -161,8 +161,6 @@ namespace MediaBrowser.Model.Configuration /// /// The dashboard source path. public string DashboardSourcePath { get; set; } - - public bool MergeMetadataAndImagesByName { get; set; } /// /// Gets or sets the image saving convention. diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index 8e934f348e..1a5c35df83 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -35,7 +35,6 @@ namespace MediaBrowser.Server.Implementations.Configuration public ServerConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer, IFileSystem fileSystem) : base(applicationPaths, logManager, xmlSerializer, fileSystem) { - UpdateItemsByNamePath(); UpdateMetadataPath(); } @@ -73,7 +72,6 @@ namespace MediaBrowser.Server.Implementations.Configuration /// protected override void OnConfigurationUpdated() { - UpdateItemsByNamePath(); UpdateMetadataPath(); base.OnConfigurationUpdated(); @@ -86,19 +84,6 @@ namespace MediaBrowser.Server.Implementations.Configuration UpdateTranscodingTempPath(); } - /// - /// Updates the items by name path. - /// - private void UpdateItemsByNamePath() - { - if (!Configuration.MergeMetadataAndImagesByName) - { - ((ServerApplicationPaths)ApplicationPaths).ItemsByNamePath = string.IsNullOrEmpty(Configuration.ItemsByNamePath) ? - null : - Configuration.ItemsByNamePath; - } - } - /// /// Updates the metadata path. /// -- cgit v1.2.3 From 16145380d90edb77f82e596e89ce98160327842c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 5 Feb 2016 12:04:38 -0500 Subject: update android init --- MediaBrowser.Api/UserLibrary/ItemsService.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'MediaBrowser.Api') diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 1c5d5b345e..761d107603 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -116,6 +116,10 @@ namespace MediaBrowser.Api.UserLibrary { item = user == null ? _libraryManager.RootFolder : user.RootFolder; } + else if (string.Equals(request.IncludeItemTypes, "BoxSet", StringComparison.OrdinalIgnoreCase)) + { + item = user == null ? _libraryManager.RootFolder : user.RootFolder; + } // Default list type = children -- cgit v1.2.3