More work for #298

pull/332/head
tidusjar 9 years ago
parent 0fa42b93f5
commit 05e4c313bf

@ -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<T> : NancyRazorViewBase<T>
{
public EmptyViewBase()
{
Layout = "Shared/Blank.cshtml";
}
public override void Execute()
{
}
}
}

@ -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;

@ -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<PlexRequestSettings> 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");
}
}
}

@ -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<AuthenticationSettings> auth, IPlexApi api, ISettingsService<PlexRequestSettings> pr) : base("userlogin", pr)
public UserLoginModule(ISettingsService<AuthenticationSettings> auth, IPlexApi api, ISettingsService<PlexRequestSettings> pr, ISettingsService<LandingPageSettings> 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<AuthenticationSettings> AuthService { get; }
private ISettingsService<LandingPageSettings> LandingPageSettings { get; }
private IPlexApi Api { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
public Negotiator Index()
public async Task<Negotiator> 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];
}

@ -160,6 +160,7 @@
<Compile Include="Bootstrapper.cs" />
<Compile Include="Helpers\BaseUrlHelper.cs" />
<Compile Include="Helpers\HeadphonesSender.cs" />
<Compile Include="Helpers\EmptyViewBase.cs" />
<Compile Include="Helpers\ServiceLocator.cs" />
<Compile Include="Helpers\StringHelper.cs" />
<Compile Include="Helpers\Themes.cs" />
@ -543,6 +544,12 @@
<Content Include="Views\Admin\LandingPage.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Views\Landing\Index.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Views\Shared\Blank.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</None>

@ -0,0 +1,3 @@
@inherits PlexRequests.UI.Helpers.EmptyViewBase<PlexRequests.Core.SettingModels.LandingPageSettings>

@ -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();
}
}
<html>
<div hidden="hidden" id="baseUrl">@baseUrl.ToHtmlString()</div>
<head>
<title>Plex Requests</title>
<!-- Styles -->
<meta name="viewport" content="width=device-width, initial-scale=1">
@Html.LoadAssets()
</head>
<body>
<div class="container">
@RenderBody()
</div>
</body>
</html>
Loading…
Cancel
Save