From 57f359e5941d47d77d050eb417b94927fcd2b6a1 Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Thu, 19 Sep 2024 13:34:24 +0200 Subject: [PATCH] [mod] oidc --- conf/example.json | 8 +- source/logic/backend.ts | 26 +++++++ source/logic/main.ts | 162 ++++++++++++++++++++++++---------------- source/style/main.css | 2 +- 4 files changed, 132 insertions(+), 66 deletions(-) diff --git a/conf/example.json b/conf/example.json index a65c065..ad0cd5a 100644 --- a/conf/example.json +++ b/conf/example.json @@ -1,3 +1,9 @@ { - "version": 1 + "version": 1, + "backend": { + "scheme": "https", + "host": "zeitbild.linke.sx", + "port": 443, + "path": "" + } } diff --git a/source/logic/backend.ts b/source/logic/backend.ts index 630cb2d..0cb6d72 100644 --- a/source/logic/backend.ts +++ b/source/logic/backend.ts @@ -138,6 +138,32 @@ namespace _zeitbild.frontend_web.backend } + /** + */ + export async function session_prepare( + ) : Promise<{kind : string; data : any;}> + { + return call( + lib_plankton.http.enum_method.get, + "/session/prepare", + { + } + ); + } + + + /** + */ + export function set_session_key( + session_key : string + ) : Promise + { + return ( + _data_chest.write("session_key", session_key) + .then(() => Promise.resolve(undefined)) + ); + } + /** */ export async function session_begin( diff --git a/source/logic/main.ts b/source/logic/main.ts index a4fff12..08c2cd8 100644 --- a/source/logic/main.ts +++ b/source/logic/main.ts @@ -19,74 +19,106 @@ namespace _zeitbild.frontend_web { "pool": { "login": async (parameters, target_element) => { - target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin( - "login", - { - "form": "", - } + const preparation : {kind : string; data : any;} = await _zeitbild.frontend_web.backend.session_prepare( ); - const form : lib_plankton.zoo_form.class_form< - {name : string; password : string;}, - {name : string; password : string;} - > = new lib_plankton.zoo_form.class_form< - {name : string; password : string;}, - {name : string; password : string;} - >( - x => x, - x => x, - new lib_plankton.zoo_input.class_input_group< - {name : string; password : string;} - >( - [ + switch (preparation.kind) { + case "internal": { + target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin( + "login", { - "name": "name", - "input": new lib_plankton.zoo_input.class_input_text(), - "label": "Name", // TODO: translate - }, - { - "name": "password", - "input": new lib_plankton.zoo_input.class_input_password(), - "label": "Kennwort", // TODO: translate - }, - ] - ), - [ - { - "label": "Anmelden", // TODO: translate - "target": "submit", - "procedure": async (get_value, get_representation) => { - const value : any = await get_value(); - try { - await _zeitbild.frontend_web.backend.session_begin( - value.name, - value.password - ); - lib_plankton.zoo_page.set( - { - "name": "events", - "parameters": {} - } - ); - } - catch (error) { - lib_plankton.zoo_page.set( - { - "name": "login", - "parameters": { - "name": value.name, - } - } - ); - } + "form": "", } - }, - ] - ); - await form.setup(document.querySelector("#login")); - await form.input_write( + ); + const form : lib_plankton.zoo_form.class_form< + {name : string; password : string;}, + {name : string; password : string;} + > = new lib_plankton.zoo_form.class_form< + {name : string; password : string;}, + {name : string; password : string;} + >( + x => x, + x => x, + new lib_plankton.zoo_input.class_input_group< + {name : string; password : string;} + >( + [ + { + "name": "name", + "input": new lib_plankton.zoo_input.class_input_text(), + "label": "Name", // TODO: translate + }, + { + "name": "password", + "input": new lib_plankton.zoo_input.class_input_password(), + "label": "Kennwort", // TODO: translate + }, + ] + ), + [ + { + "label": "Anmelden", // TODO: translate + "target": "submit", + "procedure": async (get_value, get_representation) => { + const value : any = await get_value(); + try { + await _zeitbild.frontend_web.backend.session_begin( + value.name, + value.password + ); + lib_plankton.zoo_page.set( + { + "name": "events", + "parameters": {} + } + ); + } + catch (error) { + lib_plankton.zoo_page.set( + { + "name": "login", + "parameters": { + "name": value.name, + } + } + ); + } + } + }, + ] + ); + await form.setup(document.querySelector("#login")); + await form.input_write( + { + "name": (parameters.name ?? ""), + "password": "", + } + ); + break; + } + case "oidc": { + let element_a : HTMLElement = document.createElement("a");; + element_a.textContent = lib_plankton.string.coin( + "via {{label}}", // TODO: translate + { + "label": preparation.data.label, + } + ); + element_a.setAttribute("href", preparation.data.url); + target_element.innerHTML = ""; + target_element.appendChild(element_a); + break; + } + default: { + break; + } + } + }, + "oidc_finish": async (parameters, target_element) => { + await _zeitbild.frontend_web.backend.set_session_key(parameters["session_key"]); + lib_plankton.zoo_page.set( { - "name": (parameters.name ?? ""), - "password": "", + "name": "events", + "parameters": {} } ); }, @@ -105,10 +137,12 @@ namespace _zeitbild.frontend_web const content = await _zeitbild.frontend_web.view.calendar_view_table_html( { "calendar_ids": null, + // TODO "from": { "year": 2024, "week": 37 }, + // TODO "to": { "year": 2024, "week": 43 diff --git a/source/style/main.css b/source/style/main.css index 3583fd5..80cd3f7 100644 --- a/source/style/main.css +++ b/source/style/main.css @@ -18,7 +18,7 @@ nav > ul { nav > ul > li { display: inline-block; - margin: 16px; + margin: 8px; padding: 8px; }