frontend-dali/source/widgets/login/logic.ts

127 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-10-23 23:16:11 +02:00
/*
This file is part of »dali«.
Copyright 2025 'kcf' <fenris@folksprak.org>
»dali« is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
»dali« is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with »dali«. If not, see <http://www.gnu.org/licenses/>.
*/
2025-10-28 11:38:58 +01:00
namespace _dali.widgets
2025-10-17 00:10:28 +02:00
{
/**
*/
export class class_widget_login implements lib_plankton.zoo_widget.interface_widget
{
/**
* [data]
*/
private initial_name : string;
/**
* [hook]
*/
private action_cancel : (null | (() => void));
/**
* [hook]
*/
private action_success : (null | (() => void));
/**
*/
public constructor(
{
"initial_name": initial_name = "",
"action_cancel": action_cancel = null,
"action_success": action_success = null,
}
:
{
initial_name ?: string;
action_cancel ?: (null | (() => void));
action_success ?: (null | (() => void));
}
=
{
}
)
{
this.initial_name = initial_name;
this.action_cancel = action_cancel;
this.action_success = action_success;
}
/**
* [implementation]
*/
public async load(
2025-10-28 11:38:58 +01:00
target_element : HTMLElement
2025-10-17 00:10:28 +02:00
)
: Promise<void>
{
const preparation : {kind : string; data : any;} = await _dali.backend.session_prepare(
{
"oidc_redirect_uri_template": _dali.conf.get()["misc"]["oidc_redirect_uri_template"],
}
);
switch (preparation.kind)
{
case "internal":
{
2025-10-28 11:38:58 +01:00
const sub_widget : lib_plankton.zoo_widget.interface_widget = (
new class_widget_login_internal(
preparation.data,
{
"initial_name": this.initial_name,
"action_cancel": this.action_cancel,
"action_success": this.action_success,
}
2025-10-17 00:10:28 +02:00
)
);
2025-10-28 11:38:58 +01:00
await sub_widget.load(target_element);
2025-10-17 00:10:28 +02:00
break;
}
case "oidc":
{
2025-10-28 11:38:58 +01:00
const sub_widget : lib_plankton.zoo_widget.interface_widget = (
new class_widget_login_oidc(
preparation.data,
2025-10-17 00:10:28 +02:00
{
2025-10-28 11:38:58 +01:00
"action_cancel": this.action_cancel,
"action_success": this.action_success,
2025-10-17 00:10:28 +02:00
}
2025-10-28 11:38:58 +01:00
)
);
await sub_widget.load(target_element);
2025-10-17 00:10:28 +02:00
break;
}
default:
{
2025-10-28 11:38:58 +01:00
throw (new Error("unhandled login kind: " + preparation.kind));
2025-10-17 00:10:28 +02:00
break;
}
}
}
}
}