64 lines
1.1 KiB
TypeScript
64 lines
1.1 KiB
TypeScript
namespace _aum.service.admin
|
|
{
|
|
|
|
/**
|
|
*/
|
|
export type type_value = {
|
|
name : string;
|
|
password_image : string;
|
|
};
|
|
|
|
|
|
/**
|
|
*/
|
|
function get(
|
|
name : string
|
|
) : (null | type_value)
|
|
{
|
|
const admins : Array<{name : string; password_image : string;}> = _aum.conf.get().admins;
|
|
const entry : (undefined | {name : string; password_image : string;}) = admins.find(entry_ => (entry_.name === name));
|
|
return (
|
|
(entry === undefined)
|
|
? null
|
|
: {
|
|
"name": entry.name,
|
|
"password_image": entry.password_image,
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
async function check_password(
|
|
value : type_value,
|
|
password_given : string
|
|
) : Promise<boolean>
|
|
{
|
|
return _aum.helpers.bcrypt_compare(value.password_image, password_given);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function login(
|
|
name : string,
|
|
password : string
|
|
) : Promise<(null | type_value)>
|
|
{
|
|
const value : (null | type_value) = get(name);
|
|
if (value === null) {
|
|
return null;
|
|
}
|
|
else {
|
|
if (! (await check_password(value, password))) {
|
|
return null;
|
|
}
|
|
else {
|
|
return value;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|