From 0eea53e8fecb49d505c99c578ff11c881b6db3f5 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 8 Jun 2016 14:58:12 +0100 Subject: [PATCH] Landing page stuff #298 --- PlexRequests.UI/Modules/LandingPageModule.cs | 33 +++++++++++++++++++- PlexRequests.UI/Modules/UserLoginModule.cs | 11 +++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/PlexRequests.UI/Modules/LandingPageModule.cs b/PlexRequests.UI/Modules/LandingPageModule.cs index c84b7c4fd..92a7bf72e 100644 --- a/PlexRequests.UI/Modules/LandingPageModule.cs +++ b/PlexRequests.UI/Modules/LandingPageModule.cs @@ -24,10 +24,13 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion +using System; using System.Threading.Tasks; +using Nancy; using Nancy.Responses.Negotiation; +using PlexRequests.Api.Interfaces; using PlexRequests.Core; using PlexRequests.Core.SettingModels; @@ -35,19 +38,47 @@ namespace PlexRequests.UI.Modules { public class LandingPageModule : BaseModule { - public LandingPageModule(ISettingsService settingsService, ISettingsService landing) : base("landing", settingsService) + public LandingPageModule(ISettingsService settingsService, ISettingsService landing, + ISettingsService ps, IPlexApi pApi, ISettingsService auth) : base("landing", settingsService) { LandingSettings = landing; + PlexSettings = ps; + PlexApi = pApi; + AuthSettings = auth; Get["/", true] = async (x, ct) => await Index(); + Get["/status", true] = async (x, ct) => await CheckStatus(); } private ISettingsService LandingSettings { get; } + private ISettingsService PlexSettings { get; } + private ISettingsService AuthSettings { get; } + private IPlexApi PlexApi { get; } private async Task Index() { var model = await LandingSettings.GetSettingsAsync(); return View["Index", model]; } + + private async Task CheckStatus() + { + var auth = await AuthSettings.GetSettingsAsync(); + var plexSettings = await PlexSettings.GetSettingsAsync(); + if (string.IsNullOrEmpty(auth.PlexAuthToken) || string.IsNullOrEmpty(plexSettings.Ip)) + { + return Response.AsJson(false); + } + try + { + var status = PlexApi.GetStatus(auth.PlexAuthToken, plexSettings.FullUri); + return Response.AsJson(status != null); + } + catch (Exception) + { + return Response.AsJson(false); + } + + } } } \ No newline at end of file diff --git a/PlexRequests.UI/Modules/UserLoginModule.cs b/PlexRequests.UI/Modules/UserLoginModule.cs index 92c8321d6..099545f65 100644 --- a/PlexRequests.UI/Modules/UserLoginModule.cs +++ b/PlexRequests.UI/Modules/UserLoginModule.cs @@ -66,10 +66,15 @@ namespace PlexRequests.UI.Modules public async Task Index() { - var landingSettings = await LandingPageSettings.GetSettingsAsync(); - if (landingSettings.Enabled) + var query = Request.Query["landing"]; + var landingCheck = (bool?)query ?? true; + if (landingCheck) { - return View["Landing/Index",landingSettings]; + var landingSettings = await LandingPageSettings.GetSettingsAsync(); + if (landingSettings.Enabled) + { + return View["Landing/Index", landingSettings]; + } } var settings = await AuthService.GetSettingsAsync(); return View["Index", settings];