This commit is contained in:
+29
-29
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Franzz\Spot;
|
||||
namespace Franzz\Livetrail;
|
||||
|
||||
use Franzz\Objects\PhpObject;
|
||||
use Franzz\Objects\ToolBox;
|
||||
@@ -27,7 +27,7 @@ class Controller extends PhpObject
|
||||
'logout'
|
||||
);
|
||||
|
||||
private Spot $oSpot;
|
||||
private Livetrail $oLivetrail;
|
||||
private array $asReq;
|
||||
private string $sCsrfToken = '';
|
||||
|
||||
@@ -69,22 +69,22 @@ class Controller extends PhpObject
|
||||
//Authentication and CSRF protection share the same server-side session.
|
||||
$this->initCsrfToken();
|
||||
|
||||
//Create Spot Instance
|
||||
$this->oSpot = new Spot($sProcessPage, $this->asReq['t']);
|
||||
//Create Livetrail instance
|
||||
$this->oLivetrail = new Livetrail($sProcessPage, $this->asReq['t']);
|
||||
|
||||
//Validate CSRF, then release the session lock before long-running work.
|
||||
$bValidMutationRequest = $this->validateMutationRequest($sAction);
|
||||
if(!$bValidMutationRequest || !in_array($sAction, self::SESSION_WRITING_ACTIONS, true)) $this->closeSession();
|
||||
|
||||
if(!$bValidMutationRequest) $sResult = Spot::getJsonResult(false, Spot::UNAUTHORIZED);
|
||||
if(!$bValidMutationRequest) $sResult = Livetrail::getJsonResult(false, Livetrail::UNAUTHORIZED);
|
||||
else {
|
||||
$this->oSpot->setProjectId($this->asReq['id_project']);
|
||||
$sResult = ($sAction == '')?$this->oSpot->getAppMainPage($this->getCsrfToken()):$this->dispatch($sAction);
|
||||
$this->oLivetrail->setProjectId($this->asReq['id_project']);
|
||||
$sResult = ($sAction == '')?$this->oLivetrail->getAppMainPage($this->getCsrfToken()):$this->dispatch($sAction);
|
||||
}
|
||||
|
||||
//Clean errors
|
||||
$sDebug = ob_get_clean();
|
||||
if($sDebug != '') $this->oSpot->addUncaughtError($sDebug);
|
||||
if($sDebug != '') $this->oLivetrail->addUncaughtError($sDebug);
|
||||
$this->closeSession();
|
||||
|
||||
return $sResult;
|
||||
@@ -140,36 +140,36 @@ class Controller extends PhpObject
|
||||
private function dispatch(string $sAction): string
|
||||
{
|
||||
return match($sAction) {
|
||||
'markers' => $this->oSpot->getMarkers(),
|
||||
'last_update' => $this->oSpot->getLastUpdate(),
|
||||
'next_feed' => $this->oSpot->getNextFeed($this->asReq['id']),
|
||||
'new_feed' => $this->oSpot->getNewFeed($this->asReq['id']),
|
||||
'add_post' => $this->oSpot->addPost($this->asReq['name'], $this->asReq['content']),
|
||||
'subscribe' => $this->oSpot->subscribe(),
|
||||
'unsubscribe' => $this->oSpot->unsubscribe(),
|
||||
'login' => $this->oSpot->login($this->asReq['email'], $this->asReq['password'], $this->asReq['name']),
|
||||
'logout' => $this->oSpot->logout(),
|
||||
'update_project' => $this->oSpot->updateProject(),
|
||||
'markers' => $this->oLivetrail->getMarkers(),
|
||||
'last_update' => $this->oLivetrail->getLastUpdate(),
|
||||
'next_feed' => $this->oLivetrail->getNextFeed($this->asReq['id']),
|
||||
'new_feed' => $this->oLivetrail->getNewFeed($this->asReq['id']),
|
||||
'add_post' => $this->oLivetrail->addPost($this->asReq['name'], $this->asReq['content']),
|
||||
'subscribe' => $this->oLivetrail->subscribe(),
|
||||
'unsubscribe' => $this->oLivetrail->unsubscribe(),
|
||||
'login' => $this->oLivetrail->login($this->asReq['email'], $this->asReq['password'], $this->asReq['name']),
|
||||
'logout' => $this->oLivetrail->logout(),
|
||||
'update_project' => $this->oLivetrail->updateProject(),
|
||||
default => $this->dispatchAdmin($sAction)
|
||||
};
|
||||
}
|
||||
|
||||
private function dispatchAdmin(string $sAction): string
|
||||
{
|
||||
if(!$this->oSpot->checkUserClearance(User::CLEARANCE_ADMIN)) {
|
||||
return Spot::getJsonResult(false, Spot::NOT_FOUND);
|
||||
if(!$this->oLivetrail->checkUserClearance(User::CLEARANCE_ADMIN)) {
|
||||
return Livetrail::getJsonResult(false, Livetrail::NOT_FOUND);
|
||||
}
|
||||
|
||||
return match($sAction) {
|
||||
'upload' => $this->oSpot->upload(),
|
||||
'add_comment' => $this->oSpot->addComment($this->asReq['id_entity'], $this->asReq['content']),
|
||||
'add_position' => $this->oSpot->addPosition($this->asReq['latitude'], $this->asReq['longitude'], $this->asReq['timestamp']),
|
||||
'admin_get' => $this->oSpot->getAdminSettings(),
|
||||
'admin_set' => $this->oSpot->setAdminSettings($this->asReq['type'], $this->asReq['id_entity'], $this->asReq['field'], $this->asReq['value']),
|
||||
'admin_create' => $this->oSpot->createAdminSettings($this->asReq['type']),
|
||||
'admin_delete' => $this->oSpot->deleteAdminSettings($this->asReq['type'], $this->asReq['id_entity']),
|
||||
'sql' => $this->oSpot->getDbBuildScript(),
|
||||
default => Spot::getJsonResult(false, Spot::NOT_FOUND)
|
||||
'upload' => $this->oLivetrail->upload(),
|
||||
'add_comment' => $this->oLivetrail->addComment($this->asReq['id_entity'], $this->asReq['content']),
|
||||
'add_position' => $this->oLivetrail->addPosition($this->asReq['latitude'], $this->asReq['longitude'], $this->asReq['timestamp']),
|
||||
'admin_get' => $this->oLivetrail->getAdminSettings(),
|
||||
'admin_set' => $this->oLivetrail->setAdminSettings($this->asReq['type'], $this->asReq['id_entity'], $this->asReq['field'], $this->asReq['value']),
|
||||
'admin_create' => $this->oLivetrail->createAdminSettings($this->asReq['type']),
|
||||
'admin_delete' => $this->oLivetrail->deleteAdminSettings($this->asReq['type'], $this->asReq['id_entity']),
|
||||
'sql' => $this->oLivetrail->getDbBuildScript(),
|
||||
default => Livetrail::getJsonResult(false, Livetrail::NOT_FOUND)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user