From 05e4c313bf9504daa2bf4019307e2d56a58de6fd Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 7 Jun 2016 16:22:05 +0100 Subject: [PATCH] More work for #298 --- PlexRequests.UI/Helpers/EmptyViewBase.cs | 44 ++++++++++++++++++++++ PlexRequests.UI/Modules/BaseAuthModule.cs | 8 +--- PlexRequests.UI/Modules/IndexModule.cs | 11 ++++-- PlexRequests.UI/Modules/UserLoginModule.cs | 17 +++++++-- PlexRequests.UI/PlexRequests.UI.csproj | 7 ++++ PlexRequests.UI/Views/Landing/Index.cshtml | 3 ++ PlexRequests.UI/Views/Shared/Blank.cshtml | 31 +++++++++++++++ 7 files changed, 108 insertions(+), 13 deletions(-) create mode 100644 PlexRequests.UI/Helpers/EmptyViewBase.cs create mode 100644 PlexRequests.UI/Views/Landing/Index.cshtml create mode 100644 PlexRequests.UI/Views/Shared/Blank.cshtml diff --git a/PlexRequests.UI/Helpers/EmptyViewBase.cs b/PlexRequests.UI/Helpers/EmptyViewBase.cs new file mode 100644 index 000000000..ac8dccdc6 --- /dev/null +++ b/PlexRequests.UI/Helpers/EmptyViewBase.cs @@ -0,0 +1,44 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: EmptyViewBase.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion +using Nancy.ViewEngines.Razor; + +namespace PlexRequests.UI.Helpers +{ + public class EmptyViewBase : NancyRazorViewBase + { + + public EmptyViewBase() + { + Layout = "Shared/Blank.cshtml"; + } + + public override void Execute() + { + + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/Modules/BaseAuthModule.cs b/PlexRequests.UI/Modules/BaseAuthModule.cs index 2d6bbffee..4ea42904a 100644 --- a/PlexRequests.UI/Modules/BaseAuthModule.cs +++ b/PlexRequests.UI/Modules/BaseAuthModule.cs @@ -65,11 +65,7 @@ namespace PlexRequests.UI.Modules return false; } var claims = Context.CurrentUser.Claims.ToList(); - if (claims.Contains(UserClaims.Admin) || claims.Contains(UserClaims.PowerUser)) - { - return true; - } - return false; + return claims.Contains(UserClaims.Admin) || claims.Contains(UserClaims.PowerUser); } } @@ -105,7 +101,7 @@ namespace PlexRequests.UI.Modules var baseUrl = settings.BaseUrl; var redirectPath = string.IsNullOrEmpty(baseUrl) ? "~/userlogin" : $"~/{baseUrl}/userlogin"; - + return Session[SessionKeys.UsernameKey] == null ? Context.GetRedirect(redirectPath) : null; diff --git a/PlexRequests.UI/Modules/IndexModule.cs b/PlexRequests.UI/Modules/IndexModule.cs index 81cdfa7e2..80ed7947b 100644 --- a/PlexRequests.UI/Modules/IndexModule.cs +++ b/PlexRequests.UI/Modules/IndexModule.cs @@ -24,8 +24,8 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion -using Nancy; using Nancy.Extensions; +using Nancy.Responses; using PlexRequests.Core; using PlexRequests.Core.SettingModels; @@ -36,9 +36,14 @@ namespace PlexRequests.UI.Modules { public IndexModule(ISettingsService pr) : base(pr) { - Get["/"] = parameters => Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/search" : "~/search"); + Get["/"] = x => Index(); - Get["/Index"] = parameters => Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/search" : "~/search"); + Get["/Index"] = x => Index(); + } + + public RedirectResponse Index() + { + return Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/search" : "~/search"); } } } \ No newline at end of file diff --git a/PlexRequests.UI/Modules/UserLoginModule.cs b/PlexRequests.UI/Modules/UserLoginModule.cs index d6acb5343..92c8321d6 100644 --- a/PlexRequests.UI/Modules/UserLoginModule.cs +++ b/PlexRequests.UI/Modules/UserLoginModule.cs @@ -28,9 +28,11 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Nancy; using Nancy.Extensions; +using Nancy.Responses; using Nancy.Responses.Negotiation; using NLog; @@ -46,23 +48,30 @@ namespace PlexRequests.UI.Modules { public class UserLoginModule : BaseModule { - public UserLoginModule(ISettingsService auth, IPlexApi api, ISettingsService pr) : base("userlogin", pr) + public UserLoginModule(ISettingsService auth, IPlexApi api, ISettingsService pr, ISettingsService lp) : base("userlogin", pr) { AuthService = auth; + LandingPageSettings = lp; Api = api; - Get["/"] = _ => Index(); + Get["/", true] = async (x, ct) => await Index(); Post["/"] = x => LoginUser(); Get["/logout"] = x => Logout(); } private ISettingsService AuthService { get; } + private ISettingsService LandingPageSettings { get; } private IPlexApi Api { get; } private static Logger Log = LogManager.GetCurrentClassLogger(); - public Negotiator Index() + public async Task Index() { - var settings = AuthService.GetSettings(); + var landingSettings = await LandingPageSettings.GetSettingsAsync(); + if (landingSettings.Enabled) + { + return View["Landing/Index",landingSettings]; + } + var settings = await AuthService.GetSettingsAsync(); return View["Index", settings]; } diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index 3490fa732..bfa1654d9 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -160,6 +160,7 @@ + @@ -543,6 +544,12 @@ Always + + Always + + + Always + web.config diff --git a/PlexRequests.UI/Views/Landing/Index.cshtml b/PlexRequests.UI/Views/Landing/Index.cshtml new file mode 100644 index 000000000..09d431a65 --- /dev/null +++ b/PlexRequests.UI/Views/Landing/Index.cshtml @@ -0,0 +1,3 @@ +@inherits PlexRequests.UI.Helpers.EmptyViewBase + + diff --git a/PlexRequests.UI/Views/Shared/Blank.cshtml b/PlexRequests.UI/Views/Shared/Blank.cshtml new file mode 100644 index 000000000..bbb31e108 --- /dev/null +++ b/PlexRequests.UI/Views/Shared/Blank.cshtml @@ -0,0 +1,31 @@ +@using Nancy.Security +@using Nancy.Session +@using PlexRequests.UI.Helpers +@using PlexRequests.UI.Models +@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase +@{ + var baseUrl = Html.GetBaseUrl(); + var url = string.Empty; + if (!string.IsNullOrEmpty(baseUrl.ToHtmlString())) + { + url = "/" + baseUrl.ToHtmlString(); + } +} + + + + Plex Requests + + + + @Html.LoadAssets() + + + + +
+ @RenderBody() +
+ + +