2022-04-26 19:48:03 +00:00
|
|
|
<?php
|
|
|
|
namespace fox\auth;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Class fox\auth\session
|
|
|
|
*
|
|
|
|
* @copyright MX STAR LLC 2018-2022
|
|
|
|
* @version 4.0.0
|
|
|
|
* @author Pavel Dmitriev
|
|
|
|
* @license GPLv3
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
|
|
|
use fox\externalCallable;
|
|
|
|
use fox\foxException;
|
|
|
|
use fox\request;
|
|
|
|
use fox\modules;
|
2022-05-12 13:59:48 +00:00
|
|
|
use fox\foxRequestResult;
|
2022-08-23 21:40:48 +00:00
|
|
|
use fox\moduleInfo;
|
2022-04-26 19:48:03 +00:00
|
|
|
|
|
|
|
class session implements externalCallable
|
|
|
|
{
|
|
|
|
|
|
|
|
public static function APICall(request $request)
|
|
|
|
{
|
|
|
|
switch ($request->method) {
|
|
|
|
case "DELETE":
|
|
|
|
if (! ($request->authOK)) {
|
|
|
|
throw new foxException("Bad request", 501);
|
|
|
|
}
|
|
|
|
|
|
|
|
$request->token->delete();
|
2022-05-12 13:59:48 +00:00
|
|
|
foxRequestResult::throw(200,"Deleted");
|
2022-04-26 19:48:03 +00:00
|
|
|
case "GET":
|
|
|
|
if ($request->authOK) {
|
|
|
|
$modules=[];
|
|
|
|
$i = 0;
|
2022-08-23 21:40:48 +00:00
|
|
|
|
2022-04-26 19:48:03 +00:00
|
|
|
foreach (modules::listInstalled() as $mod) {
|
2022-05-12 13:59:48 +00:00
|
|
|
if ($request->user->checkAccess($mod->globalAccessKey, $mod->name)) {
|
2022-04-26 19:48:03 +00:00
|
|
|
$i ++;
|
|
|
|
$modules[($mod->modPriority * 100) + $i] = [
|
|
|
|
"name" => $mod->name,
|
|
|
|
"instanceOf" => $mod->instanceOf,
|
|
|
|
"menu" => $mod->menuItem,
|
|
|
|
"globalAccesKey" => $mod->globalAccessKey,
|
|
|
|
"languages" => $mod->languages
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-23 21:40:48 +00:00
|
|
|
|
2022-04-26 19:48:03 +00:00
|
|
|
return [
|
|
|
|
"updated" => time(),
|
|
|
|
"user" => $request->token->user,
|
|
|
|
"acls" => $request->user->getAccessRules(),
|
2022-08-23 21:40:48 +00:00
|
|
|
"modules" => $modules,
|
2022-04-26 19:48:03 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
throw new foxException("Unauthorized", 401);
|
|
|
|
break;
|
2022-05-12 13:59:48 +00:00
|
|
|
default:
|
|
|
|
throw new foxException("Method not allowe", 405);
|
|
|
|
break;
|
2022-04-26 19:48:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|