Fixed an issue where there were some JS errors on the landing page settings and stopped us being redirected to the login sometimes as an admin

This commit is contained in:
tidusjar 2016-08-25 21:43:49 +01:00
parent c235018e98
commit 2aebbe0259
3 changed files with 159 additions and 151 deletions

View file

@ -118,9 +118,10 @@ namespace PlexRequests.UI.Helpers
public static IHtmlString LoadDateTimePickerAsset(this HtmlHelpers helper) public static IHtmlString LoadDateTimePickerAsset(this HtmlHelpers helper)
{ {
var startUrl = GetBaseUrl(); var content = GetBaseUrl();
var sb = new StringBuilder(); var sb = new StringBuilder();
var startUrl = $"{content}/Content";
sb.AppendLine($"<link rel=\"stylesheet\" href=\"{startUrl}/datepicker.min.css\" type=\"text/css\"/>"); sb.AppendLine($"<link rel=\"stylesheet\" href=\"{startUrl}/datepicker.min.css\" type=\"text/css\"/>");
sb.AppendLine($"<script src=\"{startUrl}/bootstrap-datetimepicker.min.js\"></script>"); sb.AppendLine($"<script src=\"{startUrl}/bootstrap-datetimepicker.min.js\"></script>");

View file

@ -122,7 +122,7 @@ namespace PlexRequests.UI.Modules
{ {
get get
{ {
if (Context?.CurrentUser == null) if (!LoggedIn)
{ {
return false; return false;
} }
@ -130,6 +130,9 @@ namespace PlexRequests.UI.Modules
return claims.Contains(UserClaims.Admin) || claims.Contains(UserClaims.PowerUser); return claims.Contains(UserClaims.Admin) || claims.Contains(UserClaims.PowerUser);
} }
} }
protected bool LoggedIn => Context?.CurrentUser != null;
protected string Culture { get; set; } protected string Culture { get; set; }
protected const string CultureCookieName = "_culture"; protected const string CultureCookieName = "_culture";
protected Response SetCookie() protected Response SetCookie()

View file

@ -30,6 +30,7 @@ using System.Dynamic;
using Nancy; using Nancy;
using Nancy.Authentication.Forms; using Nancy.Authentication.Forms;
using Nancy.Extensions; using Nancy.Extensions;
using Nancy.Linker;
using Nancy.Responses.Negotiation; using Nancy.Responses.Negotiation;
using Nancy.Security; using Nancy.Security;
@ -42,20 +43,22 @@ namespace PlexRequests.UI.Modules
{ {
public class LoginModule : BaseModule public class LoginModule : BaseModule
{ {
public LoginModule(ISettingsService<PlexRequestSettings> pr, ICustomUserMapper m) : base(pr) public LoginModule(ISettingsService<PlexRequestSettings> pr, ICustomUserMapper m, IResourceLinker linker) : base(pr)
{ {
UserMapper = m; UserMapper = m;
Get["/login"] = _ => Get["/login"] = _ =>
{ {
if (LoggedIn)
{ {
var url = linker.BuildRelativeUri(Context, "SearchIndex");
return Response.AsRedirect(url.ToString());
}
dynamic model = new ExpandoObject(); dynamic model = new ExpandoObject();
model.Redirect = Request.Query.redirect.Value ?? string.Empty; model.Redirect = Request.Query.redirect.Value ?? string.Empty;
model.Errored = Request.Query.error.HasValue; model.Errored = Request.Query.error.HasValue;
var adminCreated = UserMapper.DoUsersExist(); var adminCreated = UserMapper.DoUsersExist();
model.AdminExists = adminCreated; model.AdminExists = adminCreated;
return View["Index", model]; return View["Index", model];
}
}; };
Get["/logout"] = x => this.LogoutAndRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/" : "~/"); Get["/logout"] = x => this.LogoutAndRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/" : "~/");
@ -80,7 +83,8 @@ namespace PlexRequests.UI.Modules
} }
Session[SessionKeys.UsernameKey] = username; Session[SessionKeys.UsernameKey] = username;
Session[SessionKeys.ClientDateTimeOffsetKey] = dtOffset; Session[SessionKeys.ClientDateTimeOffsetKey] = dtOffset;
if(redirect.Contains("userlogin")){ if (redirect.Contains("userlogin"))
{
redirect = !string.IsNullOrEmpty(BaseUrl) ? $"/{BaseUrl}/search" : "/search"; redirect = !string.IsNullOrEmpty(BaseUrl) ? $"/{BaseUrl}/search" : "/search";
} }
return this.LoginAndRedirect(userId.Value, expiry, redirect); return this.LoginAndRedirect(userId.Value, expiry, redirect);