Fixed exception and all areas will now use the base url #72

pull/158/head
tidusjar 9 years ago
parent 866b6d6d6d
commit 6dea8b7440

@ -26,7 +26,7 @@
#endregion #endregion
using System.Net; using System.Net;
using FluentScheduler;
using Mono.Data.Sqlite; using Mono.Data.Sqlite;
using Nancy; using Nancy;
@ -40,7 +40,6 @@ using Nancy.TinyIoc;
using PlexRequests.Api; using PlexRequests.Api;
using PlexRequests.Api.Interfaces; using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Mocks;
using PlexRequests.Core; using PlexRequests.Core;
using PlexRequests.Core.SettingModels; using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers; using PlexRequests.Helpers;
@ -51,8 +50,6 @@ using PlexRequests.Store;
using PlexRequests.Store.Models; using PlexRequests.Store.Models;
using PlexRequests.Store.Repository; using PlexRequests.Store.Repository;
using PlexRequests.UI.Helpers; using PlexRequests.UI.Helpers;
using PlexRequests.UI.Jobs;
using TaskFactory = FluentScheduler.TaskFactory;
namespace PlexRequests.UI namespace PlexRequests.UI
{ {
@ -67,7 +64,7 @@ namespace PlexRequests.UI
{ {
container.Register<IUserMapper, UserMapper>(); container.Register<IUserMapper, UserMapper>();
container.Register<ISqliteConfiguration, DbConfiguration>(new DbConfiguration(new SqliteFactory())); container.Register<ISqliteConfiguration, DbConfiguration>(new DbConfiguration(new SqliteFactory()));
container.Register<ICacheProvider, MemoryCacheProvider>(); container.Register<ICacheProvider, MemoryCacheProvider>().AsSingleton();
// Settings // Settings
container.Register<ISettingsService<PlexRequestSettings>, SettingsServiceV2<PlexRequestSettings>>(); container.Register<ISettingsService<PlexRequestSettings>, SettingsServiceV2<PlexRequestSettings>>();
@ -109,6 +106,8 @@ namespace PlexRequests.UI
SubscribeAllObservers(container); SubscribeAllObservers(container);
base.ConfigureRequestContainer(container, context); base.ConfigureRequestContainer(container, context);
var loc = ServiceLocator.Instance;
loc.SetContainer(container);
} }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)

@ -35,9 +35,13 @@ namespace PlexRequests.UI.Helpers
Singleton = new ServiceLocator(); Singleton = new ServiceLocator();
} }
private static ServiceLocator Singleton { get; } private static ServiceLocator Singleton { get; }
private TinyIoCContainer Container => TinyIoCContainer.Current; private TinyIoCContainer Container { get; set; }
public static ServiceLocator Instance => Singleton; public static ServiceLocator Instance => Singleton;
public void SetContainer(TinyIoCContainer con)
{
Container = con;
}
public T Resolve<T>() where T : class public T Resolve<T>() where T : class
{ {
if (Container != null) if (Container != null)

@ -56,7 +56,7 @@ using Nancy.Security;
namespace PlexRequests.UI.Modules namespace PlexRequests.UI.Modules
{ {
public class AdminModule : NancyModule public class AdminModule : BaseModule
{ {
private ISettingsService<PlexRequestSettings> PrService { get; } private ISettingsService<PlexRequestSettings> PrService { get; }
private ISettingsService<CouchPotatoSettings> CpService { get; } private ISettingsService<CouchPotatoSettings> CpService { get; }
@ -181,8 +181,16 @@ namespace PlexRequests.UI.Modules
var result = AuthService.SaveSettings(model); var result = AuthService.SaveSettings(model);
if (result) if (result)
{ {
if (!string.IsNullOrEmpty(BaseUrl))
{
return Context.GetRedirect($"~/{BaseUrl}/admin/authentication");
}
return Context.GetRedirect("~/admin/authentication"); return Context.GetRedirect("~/admin/authentication");
} }
if (!string.IsNullOrEmpty(BaseUrl))
{
return Context.GetRedirect($"~/{BaseUrl}/error"); //TODO create error page
}
return Context.GetRedirect("~/error"); //TODO create error page return Context.GetRedirect("~/error"); //TODO create error page
} }
@ -201,8 +209,7 @@ namespace PlexRequests.UI.Modules
PrService.SaveSettings(model); PrService.SaveSettings(model);
return Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/admin" : "~/admin");
return Context.GetRedirect("~/admin");
} }
private Response RequestAuthToken() private Response RequestAuthToken()

@ -35,10 +35,12 @@ namespace PlexRequests.UI.Modules
public class BaseModule : NancyModule public class BaseModule : NancyModule
{ {
protected ServiceLocator Locator => ServiceLocator.Instance; protected ServiceLocator Locator => ServiceLocator.Instance;
protected string BaseUrl { get; set; }
public BaseModule() public BaseModule()
{ {
var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().GetSettings(); var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().GetSettings();
var baseUrl = settings.BaseUrl; var baseUrl = settings.BaseUrl;
BaseUrl = baseUrl;
var modulePath = string.IsNullOrEmpty(baseUrl) ? string.Empty : baseUrl; var modulePath = string.IsNullOrEmpty(baseUrl) ? string.Empty : baseUrl;
@ -49,6 +51,7 @@ namespace PlexRequests.UI.Modules
{ {
var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().GetSettings(); var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().GetSettings();
var baseUrl = settings.BaseUrl; var baseUrl = settings.BaseUrl;
BaseUrl = baseUrl;
var settingModulePath = string.IsNullOrEmpty(baseUrl) ? modulePath : $"{baseUrl}/{modulePath}"; var settingModulePath = string.IsNullOrEmpty(baseUrl) ? modulePath : $"{baseUrl}/{modulePath}";

@ -33,8 +33,9 @@ namespace PlexRequests.UI.Modules
{ {
public IndexModule() public IndexModule()
{ {
Get["/"] = parameters => Context.GetRedirect("~/search"); Get["/"] = parameters => Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/search" : "~/search");
Get["/Index"] = parameters => Context.GetRedirect("~/search");
Get["/Index"] = parameters => Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/search" : "~/search");
} }
} }
} }

@ -38,7 +38,7 @@ using PlexRequests.UI.Models;
namespace PlexRequests.UI.Modules namespace PlexRequests.UI.Modules
{ {
public class LoginModule : NancyModule public class LoginModule : BaseModule
{ {
public LoginModule() public LoginModule()
{ {
@ -54,7 +54,7 @@ namespace PlexRequests.UI.Modules
}; };
Get["/logout"] = x => this.LogoutAndRedirect("~/"); Get["/logout"] = x => this.LogoutAndRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/" : "~/");
Post["/login"] = x => Post["/login"] = x =>
{ {
@ -66,7 +66,7 @@ namespace PlexRequests.UI.Modules
if (userId == null) if (userId == null)
{ {
return Context.GetRedirect("~/login?error=true&username=" + username); return Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/login?error=true&username=" + username : "~/login?error=true&username=" + username);
} }
DateTime? expiry = null; DateTime? expiry = null;
if (Request.Form.RememberMe.HasValue) if (Request.Form.RememberMe.HasValue)
@ -94,7 +94,7 @@ namespace PlexRequests.UI.Modules
var exists = UserMapper.DoUsersExist(); var exists = UserMapper.DoUsersExist();
if (exists) if (exists)
{ {
return Context.GetRedirect("~/register?error=true"); return Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/register?error=true" : "~/register?error=true");
} }
var userId = UserMapper.CreateUser(username, Request.Form.Password, new[] { "Admin" }); var userId = UserMapper.CreateUser(username, Request.Form.Password, new[] { "Admin" });
Session[SessionKeys.UsernameKey] = username; Session[SessionKeys.UsernameKey] = username;

@ -155,7 +155,9 @@ namespace PlexRequests.UI.Modules
{ {
Session.Delete(SessionKeys.UsernameKey); Session.Delete(SessionKeys.UsernameKey);
} }
return Context.GetRedirect("~/userlogin"); return Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl)
? $"~/{BaseUrl}/userlogin"
: "~/userlogin");
} }
private bool CheckIfUserIsOwner(string authToken, string userName) private bool CheckIfUserIsOwner(string authToken, string userName)

Loading…
Cancel
Save