This commit is contained in:
tidusjar 2016-07-06 13:42:56 +01:00
parent d8111bcedb
commit 5bda83bfdf
4 changed files with 34 additions and 22 deletions

View file

@ -28,6 +28,7 @@ using System;
using System.Threading.Tasks;
using Nancy;
using Nancy.Linker;
using Nancy.Responses.Negotiation;
using PlexRequests.Api.Interfaces;
@ -40,40 +41,45 @@ namespace PlexRequests.UI.Modules
public class LandingPageModule : BaseModule
{
public LandingPageModule(ISettingsService<PlexRequestSettings> settingsService, ISettingsService<LandingPageSettings> landing,
ISettingsService<PlexSettings> ps, IPlexApi pApi, ISettingsService<AuthenticationSettings> auth) : base("landing", settingsService)
ISettingsService<PlexSettings> ps, IPlexApi pApi, ISettingsService<AuthenticationSettings> auth, IResourceLinker linker) : base("landing", settingsService)
{
LandingSettings = landing;
PlexSettings = ps;
PlexApi = pApi;
AuthSettings = auth;
Linker = linker;
Get["/", true] = async (x, ct) => await Index();
Get["LandingPageIndex","/", true] = async (x, ct) =>
{
var s = await LandingSettings.GetSettingsAsync();
if (!s.BeforeLogin && string.IsNullOrEmpty(Username)) //We are signed in
{
var url = Linker.BuildAbsoluteUri(Context, "SearchIndex").ToString();
return Response.AsRedirect(url);
}
var model = new LandingPageViewModel
{
Enabled = s.Enabled,
Id = s.Id,
EnabledNoticeTime = s.EnabledNoticeTime,
NoticeEnable = s.NoticeEnable,
NoticeEnd = s.NoticeEnd,
NoticeMessage = s.NoticeMessage,
NoticeStart = s.NoticeStart,
ContinueUrl = s.BeforeLogin ? $"userlogin" : $"search"
};
return View["Landing/Index", model];
};
Get["/status", true] = async (x, ct) => await CheckStatus();
}
private ISettingsService<LandingPageSettings> LandingSettings { get; }
private ISettingsService<PlexSettings> PlexSettings { get; }
private ISettingsService<AuthenticationSettings> AuthSettings { get; }
private IPlexApi PlexApi { get; }
private async Task<Negotiator> Index()
{
var s = await LandingSettings.GetSettingsAsync();
var model = new LandingPageViewModel
{
Enabled = s.Enabled,
Id = s.Id,
EnabledNoticeTime = s.EnabledNoticeTime,
NoticeEnable = s.NoticeEnable,
NoticeEnd = s.NoticeEnd,
NoticeMessage = s.NoticeMessage,
NoticeStart = s.NoticeStart,
ContinueUrl = s.BeforeLogin ? $"userlogin" : $"search"
};
return View["Landing/Index", model];
}
private IResourceLinker Linker { get; }
private async Task<Response> CheckStatus()
{