diff --git a/brain/api/v1/PagesAPI.inc.php b/brain/api/v1/PagesAPI.inc.php new file mode 100644 index 0000000..d54b830 --- /dev/null +++ b/brain/api/v1/PagesAPI.inc.php @@ -0,0 +1,31 @@ +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; + } +} diff --git a/brain/controller/APIControl.inc.php b/brain/controller/APIControl.inc.php index 282b8fa..3486492 100644 --- a/brain/controller/APIControl.inc.php +++ b/brain/controller/APIControl.inc.php @@ -3,6 +3,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; include "../brain/api/v1/ImagesAPI.inc.php"; +include "../brain/api/v1/PagesAPI.inc.php"; class APIControl { @@ -36,7 +37,7 @@ class APIControl } //there's only one verion of the api for now - //$result = []; + $result = []; switch (isset($args["third"]) ? $args["third"] : "none") { case "login": $result = Auth::login($body); @@ -45,36 +46,16 @@ class APIControl $result = Auth::logout($body); break; case "page": - //move methdology to its own API class - $task = $args["fourth"]; $token = $request->getHeader("fipamo-access-token"); + //Verify token for admin tasks if (Session::verifyToken($token[0])) { - 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; - } + $result = PagesAPI::handlePageTask($request, $args); } else { $result = [ "message" => "API access denied, homie", "type" => "API_ERROR", ]; } - break; default: $result = [ diff --git a/brain/controller/DashControl.inc.php b/brain/controller/DashControl.inc.php index d21a8b6..7e1cd61 100644 --- a/brain/controller/DashControl.inc.php +++ b/brain/controller/DashControl.inc.php @@ -17,24 +17,29 @@ class DashControl $template = ""; switch (isset($args["second"]) ? $args["second"] : "index") { case "pages": - $currentPage = isset($args["fourth"]) ? $args["fourth"] : 1; - $filter = isset($args["third"]) ? $args["third"] : "all"; - $data = (new Book("../content/pages"))->getPages( - $currentPage, - 4, - $filter - ); - $template = "dash/book.twig"; - $pageOptions = [ - "entryCount" => $data["entryCount"], - "numOfPages" => $data["numOfPages"], - "currentPage" => $currentPage, - "filter" => $data["paginate"]["sort"], - "stats" => $data["stats"], - "pages" => $data["pages"], - "paginate" => $data["paginate"], - "status" => Session::active(), - ]; + if (Session::active()) { + $currentPage = isset($args["fourth"]) ? $args["fourth"] : 1; + $filter = isset($args["third"]) ? $args["third"] : "all"; + $data = (new Book("../content/pages"))->getPages( + $currentPage, + 4, + $filter + ); + $template = "dash/book.twig"; + $pageOptions = [ + "entryCount" => $data["entryCount"], + "numOfPages" => $data["numOfPages"], + "currentPage" => $currentPage, + "filter" => $data["paginate"]["sort"], + "stats" => $data["stats"], + "pages" => $data["pages"], + "paginate" => $data["paginate"], + "status" => Session::active(), + ]; + } else { + header("Location: /dashboard"); + die(); + } break; case "page": if (Session::active()) { @@ -50,11 +55,8 @@ class DashControl "status" => Session::active(), ]; } else { - $pageOptions = [ - "title" => "Fipamo | Create Page", - "mode" => $mode, - "status" => Session::active(), - ]; + header("Location: /dashboard"); + die(); } } else { $template = "dash/start.twig";