Browse Source

added admin API method for getting site and member info

tags/b2.2.1^2
Ro 1 week ago
parent
commit
83b4aff716
4 changed files with 117 additions and 7 deletions
  1. +44
    -0
      brain/api/v1/SettingsAPI.inc.php
  2. +19
    -2
      brain/controller/APIControl.inc.php
  3. +4
    -4
      public/assets/scripts/dash.min.js
  4. +50
    -1
      src/libraries/FipamoAdminAPI.js

+ 44
- 0
brain/api/v1/SettingsAPI.inc.php 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();


+ 19
- 2
brain/controller/APIControl.inc.php 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()) {


+ 4
- 4
public/assets/scripts/dash.min.js
File diff suppressed because it is too large
View File


+ 50
- 1
src/libraries/FipamoAdminAPI.js 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
* @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();
}
});


Loading…
Cancel
Save