added admin API method for getting site and member info

This commit is contained in:
Ro 2021-07-21 12:46:14 -07:00
parent 13c9d05019
commit 83b4aff716
4 changed files with 117 additions and 7 deletions

View file

@ -55,6 +55,50 @@ class SettingsAPI
return $result; return $result;
} }
public static function getInfo($request, $args)
{
$task = $args["fourth"];
switch ($task) {
case "site":
$config = new Settings();
$settings = $config->getSettings();
$data = [
"title" => $settings["global"]["title"],
"base_url" => $settings["global"]["base_url"],
"description" => $settings["global"]["descriptions"],
];
$result = [
"message" => "Settings Found",
"type" => "GET_SETTINGS",
"data" => $data,
];
break;
case "member":
if (Session::active()) {
$member = $member = Session::get("member");
$data = ["handle" => $member["handle"], "email" => $member["email"]];
$result = [
"message" => "Member Info Found",
"type" => "GET_MEMBER_INFO",
"data" => $data,
];
} else {
$result = [
"message" => "Not logged in. C'mon, bruh",
"type" => "TASK_NONE",
];
}
break;
default:
$result = [
"message" => "No Settings found. Frowny Face",
"type" => "TASK_NONE",
];
break;
}
return $result;
}
public static function createBackup() public static function createBackup()
{ {
$result = Maintenance::makeBackup(); $result = Maintenance::makeBackup();

View file

@ -17,7 +17,6 @@ class APIControl
array $args array $args
): ResponseInterface { ): ResponseInterface {
$filename = ""; $filename = "";
switch (isset($args["third"]) ? $args["third"] : "none") { switch (isset($args["third"]) ? $args["third"] : "none") {
case "status": case "status":
if (Member::verifyKey($_GET["key"])) { if (Member::verifyKey($_GET["key"])) {
@ -40,7 +39,25 @@ class APIControl
"type" => "API_ERROR", "type" => "API_ERROR",
]; ];
} }
break;
case "settings":
$token = $request->getHeader("fipamo-access-token");
//Verify token to get site info
if (isset($token[0])) {
if (Session::verifyToken($token[0])) {
$result = SettingsAPI::getInfo($request, $args);
} else {
$result = [
"message" => "Invalid token, API access denied, homie",
"type" => "API_ERROR",
];
}
} else {
$result = [
"message" => "No token, API access denied, homie",
"type" => "API_ERROR",
];
}
break; break;
case "files": case "files":
if (Session::active()) { if (Session::active()) {

File diff suppressed because one or more lines are too long

View file

@ -8,7 +8,8 @@ export const CONTENT_TYPE_JSON = "json";
export const CONTENT_TYPE_FORM = "x-www-form-urlencoded"; export const CONTENT_TYPE_FORM = "x-www-form-urlencoded";
//** API URLS **// //** API URLS **//
export const API_STATUS = "/api/v1/status"; export const API_STATUS = "/api/v1/status";
export const API_GET_NAV = "/api/settings/nav"; export const API_GET_SETTINGS = "/api/v1/settings/site";
export const API_GET_MEMBER_INFO = "/api/v1/settings/member";
export const API_NEW_PAGE = "/api/v1/page/create"; export const API_NEW_PAGE = "/api/v1/page/create";
export const API_EDIT_PAGE = "/api/v1/page/write"; export const API_EDIT_PAGE = "/api/v1/page/write";
export const API_DELETE_PAGE = "/api/v1/page/delete"; export const API_DELETE_PAGE = "/api/v1/page/delete";
@ -29,6 +30,8 @@ export const TASK_SEND_MAIL = "sendMail";
export const TASK_REINDEX_PAGE = "reIndexPages"; export const TASK_REINDEX_PAGE = "reIndexPages";
export const TASK_SYNC_SETTNIGS = "syncSite"; export const TASK_SYNC_SETTNIGS = "syncSite";
export const TASK_SYNC_NAV = "syncNav"; export const TASK_SYNC_NAV = "syncNav";
export const TASK_GET_SETTINGS = "getSiteSettings";
export const TASK_GET_MEMBER_INFO = "getMemberInfo";
//** API STATUS **// //** API STATUS **//
export const API_ACCESS_GOOD = "apiUseAuthorized"; export const API_ACCESS_GOOD = "apiUseAuthorized";
export const API_ACCESS_BAD = "apiUseNotAuthorized"; export const API_ACCESS_BAD = "apiUseNotAuthorized";
@ -317,6 +320,46 @@ class FipamoAdminAPI {
}); });
} }
/**
* *Promise method for retrieving site and member info*\
* **GET** `/api/v1/settings/:type`
* @param {string} type - type of info requested
* @example
* api.getInfo("type").then(data=>{
console.log("Info Object", data);
* })
* @returns {object} json object that contains data for requested information
*
* *info object example*
* ```
{
"message":"message of affirmation!",
"task":"type of info request",
"data":json-data-object,
}
* ```
*/
getInfo(type) {
let url, task;
if (type == "site") {
url = API_GET_SETTINGS;
task = TASK_GET_SETTINGS;
} else {
url = API_GET_MEMBER_INFO;
task = TASK_GET_MEMBER_INFO;
}
return new Promise((resolve, reject) => {
this._request(this.baseURL ? this.baseURL + url : url, task)
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
});
});
}
//-------------------------- //--------------------------
// private // private
//-------------------------- //--------------------------
@ -365,6 +408,12 @@ class FipamoAdminAPI {
break; break;
} }
} else { } else {
if (
eventType === TASK_GET_SETTINGS ||
eventType === TASK_GET_MEMBER_INFO
) {
request.setRequestHeader("fipamo-access-token", self.token);
}
request.send(); request.send();
} }
}); });