196 lines
4.2 KiB
TypeScript
196 lines
4.2 KiB
TypeScript
namespace _dali.widgets.login
|
|
{
|
|
|
|
/**
|
|
*/
|
|
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(
|
|
target_element : Element
|
|
)
|
|
: 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":
|
|
{
|
|
target_element.innerHTML = await _dali.helpers.template_coin(
|
|
"widget-login",
|
|
"default",
|
|
{
|
|
}
|
|
);
|
|
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": lib_plankton.translate.get("widget.login.internal.name"),
|
|
},
|
|
{
|
|
"name": "password",
|
|
"input": new lib_plankton.zoo_input.class_input_password(),
|
|
"label": lib_plankton.translate.get("widget.login.internal.password"),
|
|
},
|
|
]
|
|
),
|
|
(
|
|
[]
|
|
.concat(
|
|
[
|
|
{
|
|
"label": lib_plankton.translate.get("widget.login.internal.do"),
|
|
"procedure": async (get_value, get_representation) => {
|
|
const value : any = await get_value();
|
|
try
|
|
{
|
|
await _dali.backend.session_begin(
|
|
value.name,
|
|
value.password
|
|
);
|
|
if (this.action_success !== null) this.action_success();
|
|
}
|
|
catch (error)
|
|
{
|
|
// todo
|
|
}
|
|
}
|
|
}
|
|
]
|
|
)
|
|
.concat(
|
|
(this.action_cancel === null)
|
|
?
|
|
[]
|
|
:
|
|
[
|
|
{
|
|
"label": lib_plankton.translate.get("common.cancel"),
|
|
"procedure": () => {
|
|
this.action_cancel();
|
|
}
|
|
}
|
|
]
|
|
)
|
|
)
|
|
);
|
|
await form.setup(document.querySelector(".widget-login"));
|
|
await form.input_write(
|
|
{
|
|
"name": this.initial_name,
|
|
"password": "",
|
|
}
|
|
);
|
|
break;
|
|
}
|
|
case "oidc":
|
|
{
|
|
// link
|
|
{
|
|
let element_a : HTMLElement = document.createElement("a");;
|
|
element_a.textContent = lib_plankton.string.coin(
|
|
lib_plankton.translate.get("widget.login.oidc.via"),
|
|
{
|
|
"title": preparation.data.label,
|
|
}
|
|
);
|
|
element_a.setAttribute("href", preparation.data.url);
|
|
target_element.appendChild(element_a);
|
|
}
|
|
{
|
|
let dom_br : HTMLElement = document.createElement("br");
|
|
target_element.appendChild(dom_br);
|
|
}
|
|
{
|
|
let dom_br : HTMLElement = document.createElement("br");
|
|
target_element.appendChild(dom_br);
|
|
}
|
|
// cancel
|
|
{
|
|
let dom_cancel : HTMLElement = document.createElement("button");
|
|
dom_cancel.textContent = lib_plankton.translate.get("common.cancel");
|
|
dom_cancel.addEventListener(
|
|
"click",
|
|
() => {
|
|
this.action_cancel();
|
|
}
|
|
);
|
|
target_element.appendChild(dom_cancel);
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
// todo
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|