From d77686e6f01b00111accbce5430871b437b9e492 Mon Sep 17 00:00:00 2001 From: exyi Date: Mon, 30 Nov 2020 22:34:15 +0000 Subject: [PATCH] User meta header for isLoggedIn --- frontend/src/ksp-task-grabber.ts | 2 +- .../Controllers/GrafikPageController.cs | 13 ++++++++++++- server/Ksp.WebServer/KspPageRewriter.cs | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/frontend/src/ksp-task-grabber.ts b/frontend/src/ksp-task-grabber.ts index 97b19bf..e35e64f 100644 --- a/frontend/src/ksp-task-grabber.ts +++ b/frontend/src/ksp-task-grabber.ts @@ -193,7 +193,7 @@ async function loadTask({ url, startElement }: TaskLocation): Promise> { diff --git a/server/Ksp.WebServer/Controllers/GrafikPageController.cs b/server/Ksp.WebServer/Controllers/GrafikPageController.cs index b1b3a62..06dfb3a 100644 --- a/server/Ksp.WebServer/Controllers/GrafikPageController.cs +++ b/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 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(); diff --git a/server/Ksp.WebServer/KspPageRewriter.cs b/server/Ksp.WebServer/KspPageRewriter.cs index ffe6577..4cfa7b8 100644 --- a/server/Ksp.WebServer/KspPageRewriter.cs +++ b/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");