Browse Source

User meta header for isLoggedIn

master
Standa Lukeš 4 years ago
parent
commit
d77686e6f0
  1. 2
      frontend/src/ksp-task-grabber.ts
  2. 13
      server/Ksp.WebServer/Controllers/GrafikPageController.cs
  3. 2
      server/Ksp.WebServer/KspPageRewriter.cs

2
frontend/src/ksp-task-grabber.ts

@ -193,7 +193,7 @@ async function loadTask({ url, startElement }: TaskLocation): Promise<TaskAssign
}
export function isLoggedIn(): boolean {
return !!document.querySelector(".auth a[href='/profil/profil.cgi']")
return !!document.head.querySelector("meta[name=x-ksp-uid]")
}
export async function grabTaskStates(kspIds: string[]): Promise<Map<string, TaskStatus>> {

13
server/Ksp.WebServer/Controllers/GrafikPageController.cs

@ -24,6 +24,8 @@ namespace Ksp.WebServer.Controllers
private readonly KspPageRewriter pageRewriter;
private readonly KspProxyConfig kspProxyConfig;
string KspAuthCookie => this.HttpContext.Request.Cookies["ksp_auth"];
public GrafikPageController(
ILogger<TasksController> logger,
IWebHostEnvironment env,
@ -59,7 +61,7 @@ namespace Ksp.WebServer.Controllers
var grafik = p.ParseDocument(grafikPage);
var kspTemplate = p.ParseDocument(await FetchBlankPage());
pageRewriter.ModifyTree(kspTemplate, "grafik");
pageRewriter.ModifyTree(kspTemplate, "kurz");
var innerBody = grafik.Body;
innerBody.Replace(kspTemplate.Body);
@ -67,6 +69,15 @@ namespace Ksp.WebServer.Controllers
page.InnerHtml = "";
page.AppendNodes(innerBody.ChildNodes.ToArray());
if (KspAuthCookie is object)
{
var user = KspAuthenticator.ParseAuthCookie(KspAuthCookie);
var metaUser = grafik.CreateElement("meta");
metaUser.SetAttribute("name", "x-ksp-uid");
metaUser.SetAttribute("content", user.Id.Value.ToString());
grafik.Head.AppendChild(metaUser);
}
foreach(var headElement in kspTemplate.Head.QuerySelectorAll("link, script"))
{
headElement.RemoveFromParent();

2
server/Ksp.WebServer/KspPageRewriter.cs

@ -38,7 +38,7 @@ namespace Ksp.WebServer
{
encyklopedie.TextContent = "Kurzy";
encyklopedie.SetAttribute("href", "/kurz");
if ("grafik" == path)
if ("kurz" == path)
{
foreach (var li in document.QuerySelectorAll("#menu ul li.active"))
li.ClassList.Remove("active");