User meta header for isLoggedIn
This commit is contained in:
parent
8c1ab26a5e
commit
d77686e6f0
3 changed files with 14 additions and 3 deletions
|
@ -193,7 +193,7 @@ async function loadTask({ url, startElement }: TaskLocation): Promise<TaskAssign
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isLoggedIn(): boolean {
|
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>> {
|
export async function grabTaskStates(kspIds: string[]): Promise<Map<string, TaskStatus>> {
|
||||||
|
|
|
@ -24,6 +24,8 @@ namespace Ksp.WebServer.Controllers
|
||||||
private readonly KspPageRewriter pageRewriter;
|
private readonly KspPageRewriter pageRewriter;
|
||||||
private readonly KspProxyConfig kspProxyConfig;
|
private readonly KspProxyConfig kspProxyConfig;
|
||||||
|
|
||||||
|
string KspAuthCookie => this.HttpContext.Request.Cookies["ksp_auth"];
|
||||||
|
|
||||||
public GrafikPageController(
|
public GrafikPageController(
|
||||||
ILogger<TasksController> logger,
|
ILogger<TasksController> logger,
|
||||||
IWebHostEnvironment env,
|
IWebHostEnvironment env,
|
||||||
|
@ -59,7 +61,7 @@ namespace Ksp.WebServer.Controllers
|
||||||
var grafik = p.ParseDocument(grafikPage);
|
var grafik = p.ParseDocument(grafikPage);
|
||||||
|
|
||||||
var kspTemplate = p.ParseDocument(await FetchBlankPage());
|
var kspTemplate = p.ParseDocument(await FetchBlankPage());
|
||||||
pageRewriter.ModifyTree(kspTemplate, "grafik");
|
pageRewriter.ModifyTree(kspTemplate, "kurz");
|
||||||
|
|
||||||
var innerBody = grafik.Body;
|
var innerBody = grafik.Body;
|
||||||
innerBody.Replace(kspTemplate.Body);
|
innerBody.Replace(kspTemplate.Body);
|
||||||
|
@ -67,6 +69,15 @@ namespace Ksp.WebServer.Controllers
|
||||||
page.InnerHtml = "";
|
page.InnerHtml = "";
|
||||||
page.AppendNodes(innerBody.ChildNodes.ToArray());
|
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"))
|
foreach(var headElement in kspTemplate.Head.QuerySelectorAll("link, script"))
|
||||||
{
|
{
|
||||||
headElement.RemoveFromParent();
|
headElement.RemoveFromParent();
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace Ksp.WebServer
|
||||||
{
|
{
|
||||||
encyklopedie.TextContent = "Kurzy";
|
encyklopedie.TextContent = "Kurzy";
|
||||||
encyklopedie.SetAttribute("href", "/kurz");
|
encyklopedie.SetAttribute("href", "/kurz");
|
||||||
if ("grafik" == path)
|
if ("kurz" == path)
|
||||||
{
|
{
|
||||||
foreach (var li in document.QuerySelectorAll("#menu ul li.active"))
|
foreach (var li in document.QuerySelectorAll("#menu ul li.active"))
|
||||||
li.ClassList.Remove("active");
|
li.ClassList.Remove("active");
|
||||||
|
|
Reference in a new issue