This commit is contained in:
+19
-6
@@ -22,6 +22,10 @@ class Controller extends PhpObject
|
|||||||
'admin_create',
|
'admin_create',
|
||||||
'admin_delete'
|
'admin_delete'
|
||||||
);
|
);
|
||||||
|
const SESSION_WRITING_ACTIONS = array(
|
||||||
|
'login',
|
||||||
|
'logout'
|
||||||
|
);
|
||||||
|
|
||||||
private Spot $oSpot;
|
private Spot $oSpot;
|
||||||
private array $asReq;
|
private array $asReq;
|
||||||
@@ -67,17 +71,21 @@ class Controller extends PhpObject
|
|||||||
|
|
||||||
//Create Spot Instance
|
//Create Spot Instance
|
||||||
$this->oSpot = new Spot($sProcessPage, $this->asReq['t']);
|
$this->oSpot = new Spot($sProcessPage, $this->asReq['t']);
|
||||||
$this->oSpot->setProjectId($this->asReq['id_project']);
|
|
||||||
|
|
||||||
//Validate CSRF & dispatch
|
//Validate CSRF, then release the session lock before long-running work.
|
||||||
if(!$this->validateMutationRequest($sAction)) $sResult = Spot::getJsonResult(false, Spot::UNAUTHORIZED);
|
$bValidMutationRequest = $this->validateMutationRequest($sAction);
|
||||||
elseif($sAction == '') $sResult = $this->oSpot->getAppMainPage($this->getCsrfToken());
|
if(!$bValidMutationRequest || !in_array($sAction, self::SESSION_WRITING_ACTIONS, true)) $this->closeSession();
|
||||||
else $sResult = $this->dispatch($sAction);
|
|
||||||
|
if(!$bValidMutationRequest) $sResult = Spot::getJsonResult(false, Spot::UNAUTHORIZED);
|
||||||
|
else {
|
||||||
|
$this->oSpot->setProjectId($this->asReq['id_project']);
|
||||||
|
$sResult = ($sAction == '')?$this->oSpot->getAppMainPage($this->getCsrfToken()):$this->dispatch($sAction);
|
||||||
|
}
|
||||||
|
|
||||||
//Clean errors
|
//Clean errors
|
||||||
$sDebug = ob_get_clean();
|
$sDebug = ob_get_clean();
|
||||||
if($sDebug != '') $this->oSpot->addUncaughtError($sDebug);
|
if($sDebug != '') $this->oSpot->addUncaughtError($sDebug);
|
||||||
if(session_status() === PHP_SESSION_ACTIVE) session_write_close();
|
$this->closeSession();
|
||||||
|
|
||||||
return $sResult;
|
return $sResult;
|
||||||
}
|
}
|
||||||
@@ -124,6 +132,11 @@ class Controller extends PhpObject
|
|||||||
return PHP_SAPI === 'cli' || ($sServerToken !== '' && is_string($sClientToken) && hash_equals($sServerToken, $sClientToken));
|
return PHP_SAPI === 'cli' || ($sServerToken !== '' && is_string($sClientToken) && hash_equals($sServerToken, $sClientToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function closeSession(): void
|
||||||
|
{
|
||||||
|
if(session_status() === PHP_SESSION_ACTIVE) session_write_close();
|
||||||
|
}
|
||||||
|
|
||||||
private function dispatch(string $sAction): string
|
private function dispatch(string $sAction): string
|
||||||
{
|
{
|
||||||
return match($sAction) {
|
return match($sAction) {
|
||||||
|
|||||||
Reference in New Issue
Block a user