moved page editing api methodology to its own api class, session check for pages section

This commit is contained in:
Ro 2021-04-14 12:01:49 -07:00
parent ed2105edcc
commit 9cf0cbfbe4
3 changed files with 60 additions and 46 deletions

View file

@ -0,0 +1,31 @@
<?php
class PagesAPI
{
public function __construct()
{
}
public static function handlePageTask($request, $args)
{
$task = $args["fourth"];
switch ($task) {
case "delete":
case "create":
case "write":
$result = (new Book("../content/pages"))->editPage($task, $request);
break;
case "add-entry-image":
$result = ImagesAPI::uploadImage($request);
break;
default:
$result = [
"message" => "Hm, no task. That's unfortunate",
"type" => "TASK_NONE",
];
break;
}
return $result;
}
}

View file

@ -3,6 +3,7 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
include "../brain/api/v1/ImagesAPI.inc.php"; include "../brain/api/v1/ImagesAPI.inc.php";
include "../brain/api/v1/PagesAPI.inc.php";
class APIControl class APIControl
{ {
@ -36,7 +37,7 @@ class APIControl
} }
//there's only one verion of the api for now //there's only one verion of the api for now
//$result = []; $result = [];
switch (isset($args["third"]) ? $args["third"] : "none") { switch (isset($args["third"]) ? $args["third"] : "none") {
case "login": case "login":
$result = Auth::login($body); $result = Auth::login($body);
@ -45,36 +46,16 @@ class APIControl
$result = Auth::logout($body); $result = Auth::logout($body);
break; break;
case "page": case "page":
//move methdology to its own API class
$task = $args["fourth"];
$token = $request->getHeader("fipamo-access-token"); $token = $request->getHeader("fipamo-access-token");
//Verify token for admin tasks
if (Session::verifyToken($token[0])) { if (Session::verifyToken($token[0])) {
switch ($task) { $result = PagesAPI::handlePageTask($request, $args);
case "delete":
case "create":
case "write":
$result = (new Book("../content/pages"))->editPage(
$task,
$request
);
break;
case "add-entry-image":
$result = ImagesAPI::uploadImage($request);
break;
default:
$result = [
"message" => "Hm, no task. That's unfortunate",
"type" => "TASK_NONE",
];
break;
}
} else { } else {
$result = [ $result = [
"message" => "API access denied, homie", "message" => "API access denied, homie",
"type" => "API_ERROR", "type" => "API_ERROR",
]; ];
} }
break; break;
default: default:
$result = [ $result = [

View file

@ -17,24 +17,29 @@ class DashControl
$template = ""; $template = "";
switch (isset($args["second"]) ? $args["second"] : "index") { switch (isset($args["second"]) ? $args["second"] : "index") {
case "pages": case "pages":
$currentPage = isset($args["fourth"]) ? $args["fourth"] : 1; if (Session::active()) {
$filter = isset($args["third"]) ? $args["third"] : "all"; $currentPage = isset($args["fourth"]) ? $args["fourth"] : 1;
$data = (new Book("../content/pages"))->getPages( $filter = isset($args["third"]) ? $args["third"] : "all";
$currentPage, $data = (new Book("../content/pages"))->getPages(
4, $currentPage,
$filter 4,
); $filter
$template = "dash/book.twig"; );
$pageOptions = [ $template = "dash/book.twig";
"entryCount" => $data["entryCount"], $pageOptions = [
"numOfPages" => $data["numOfPages"], "entryCount" => $data["entryCount"],
"currentPage" => $currentPage, "numOfPages" => $data["numOfPages"],
"filter" => $data["paginate"]["sort"], "currentPage" => $currentPage,
"stats" => $data["stats"], "filter" => $data["paginate"]["sort"],
"pages" => $data["pages"], "stats" => $data["stats"],
"paginate" => $data["paginate"], "pages" => $data["pages"],
"status" => Session::active(), "paginate" => $data["paginate"],
]; "status" => Session::active(),
];
} else {
header("Location: /dashboard");
die();
}
break; break;
case "page": case "page":
if (Session::active()) { if (Session::active()) {
@ -50,11 +55,8 @@ class DashControl
"status" => Session::active(), "status" => Session::active(),
]; ];
} else { } else {
$pageOptions = [ header("Location: /dashboard");
"title" => "Fipamo | Create Page", die();
"mode" => $mode,
"status" => Session::active(),
];
} }
} else { } else {
$template = "dash/start.twig"; $template = "dash/start.twig";