Merge branch 'develop' into beta

added admin method for getting site and member data
This commit is contained in:
Ro 2021-07-22 13:08:01 -07:00
commit 3968e32e78
4 changed files with 117 additions and 7 deletions

View file

@ -55,6 +55,50 @@ class SettingsAPI
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()
{
$result = Maintenance::makeBackup();

View file

@ -17,7 +17,6 @@ class APIControl
array $args
): ResponseInterface {
$filename = "";
switch (isset($args["third"]) ? $args["third"] : "none") {
case "status":
if (Member::verifyKey($_GET["key"])) {
@ -40,7 +39,25 @@ class APIControl
"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;
case "files":
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";
//** API URLS **//
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_EDIT_PAGE = "/api/v1/page/write";
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_SYNC_SETTNIGS = "syncSite";
export const TASK_SYNC_NAV = "syncNav";
export const TASK_GET_SETTINGS = "getSiteSettings";
export const TASK_GET_MEMBER_INFO = "getMemberInfo";
//** API STATUS **//
export const API_ACCESS_GOOD = "apiUseAuthorized";
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 ['site'|'member'];
* @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
//--------------------------
@ -365,6 +408,12 @@ class FipamoAdminAPI {
break;
}
} else {
if (
eventType === TASK_GET_SETTINGS ||
eventType === TASK_GET_MEMBER_INFO
) {
request.setRequestHeader("fipamo-access-token", self.token);
}
request.send();
}
});