Landing page stuff #298

pull/332/head
tidusjar 9 years ago
parent 7d03d296fd
commit 0eea53e8fe

@ -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<PlexRequestSettings> settingsService, ISettingsService<LandingPageSettings> landing) : base("landing", settingsService)
public LandingPageModule(ISettingsService<PlexRequestSettings> settingsService, ISettingsService<LandingPageSettings> landing,
ISettingsService<PlexSettings> ps, IPlexApi pApi, ISettingsService<AuthenticationSettings> 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<LandingPageSettings> LandingSettings { get; }
private ISettingsService<PlexSettings> PlexSettings { get; }
private ISettingsService<AuthenticationSettings> AuthSettings { get; }
private IPlexApi PlexApi { get; }
private async Task<Negotiator> Index()
{
var model = await LandingSettings.GetSettingsAsync();
return View["Index", model];
}
private async Task<Response> 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);
}
}
}
}

@ -65,11 +65,16 @@ namespace PlexRequests.UI.Modules
private static Logger Log = LogManager.GetCurrentClassLogger();
public async Task<Negotiator> Index()
{
var query = Request.Query["landing"];
var landingCheck = (bool?)query ?? true;
if (landingCheck)
{
var landingSettings = await LandingPageSettings.GetSettingsAsync();
if (landingSettings.Enabled)
{
return View["Landing/Index",landingSettings];
return View["Landing/Index", landingSettings];
}
}
var settings = await AuthService.GetSettingsAsync();
return View["Index", settings];

Loading…
Cancel
Save