103 lines
1.1 KiB
TypeScript
103 lines
1.1 KiB
TypeScript
|
|
namespace _dali
|
||
|
|
{
|
||
|
|
|
||
|
|
/**
|
||
|
|
*/
|
||
|
|
let _actions_login : Array<(() => Promise<void>)> = [];
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
*/
|
||
|
|
let _actions_logout : Array<(() => Promise<void>)> = [];
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
*/
|
||
|
|
let _is_logged_in : boolean = false;
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
*/
|
||
|
|
export function listen_login(
|
||
|
|
action : (() => Promise<void>)
|
||
|
|
)
|
||
|
|
: void
|
||
|
|
{
|
||
|
|
_actions_login.push(action);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
*/
|
||
|
|
export function listen_logout(
|
||
|
|
action : (() => Promise<void>)
|
||
|
|
)
|
||
|
|
: void
|
||
|
|
{
|
||
|
|
_actions_logout.push(action);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
*/
|
||
|
|
export async function notify_login(
|
||
|
|
)
|
||
|
|
: Promise<void>
|
||
|
|
{
|
||
|
|
_is_logged_in = true;
|
||
|
|
for (const action of _actions_login)
|
||
|
|
{
|
||
|
|
await action();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
*/
|
||
|
|
export async function notify_logout(
|
||
|
|
)
|
||
|
|
: Promise<void>
|
||
|
|
{
|
||
|
|
_is_logged_in = false;
|
||
|
|
for (const action of _actions_logout)
|
||
|
|
{
|
||
|
|
await action();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
*/
|
||
|
|
export function is_logged_in(
|
||
|
|
)
|
||
|
|
: boolean
|
||
|
|
{
|
||
|
|
return _is_logged_in;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
*/
|
||
|
|
export async function logout(
|
||
|
|
)
|
||
|
|
: Promise<void>
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
await _dali.backend.session_end(
|
||
|
|
);
|
||
|
|
notify_logout();
|
||
|
|
}
|
||
|
|
catch (error)
|
||
|
|
{
|
||
|
|
lib_plankton.log.notice(
|
||
|
|
"dali.logout_failed",
|
||
|
|
{
|
||
|
|
"reason": String(error),
|
||
|
|
}
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|