|
@@ -12,49 +12,50 @@ use OpenMind\System\User;
|
|
|
|
|
|
|
|
class Controller
|
|
class Controller
|
|
|
{
|
|
{
|
|
|
- /** @var SQL $dbHandle OM-Link Database */
|
|
|
|
|
- protected $dbHandle;
|
|
|
|
|
|
|
+ /** @var SQL $dbHandle OM-Link Database */
|
|
|
|
|
+ protected $dbHandle;
|
|
|
private $timeLoadStart = null;
|
|
private $timeLoadStart = null;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Sanitized POST request, useful if sanitized POST is need
|
|
|
|
|
- * @var array $sanitizedPostRequest
|
|
|
|
|
- */
|
|
|
|
|
- private $sanitizedPostRequest;
|
|
|
|
|
|
|
+ * Sanitized POST request, useful if sanitized POST is need
|
|
|
|
|
+ * @var array $sanitizedPostRequest
|
|
|
|
|
+ */
|
|
|
|
|
+ private $sanitizedPostRequest;
|
|
|
|
|
|
|
|
- public function __construct($f3)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public function __construct($f3)
|
|
|
|
|
+ {
|
|
|
$this->timeLoadStart = round(microtime(true) * 1000);
|
|
$this->timeLoadStart = round(microtime(true) * 1000);
|
|
|
|
|
|
|
|
- $this->sanitizedPostRequest = $f3->clean($f3->get('POST'));
|
|
|
|
|
- $this->dbHandle = $f3->get('DB');
|
|
|
|
|
|
|
+ $this->sanitizedPostRequest = $f3->clean($f3->get('POST'));
|
|
|
|
|
+ $this->dbHandle = $f3->get('DB');
|
|
|
|
|
+
|
|
|
|
|
+ /** @var User $loggedUser */
|
|
|
|
|
+ $loggedUser = $f3->exists('SESSION.user') ? User::Restore() : null;
|
|
|
|
|
|
|
|
- /** @var \OpenMind\System\User $loggedUser */
|
|
|
|
|
- $loggedUser = $f3->exists('SESSION.user') ? User::Restore() : null;
|
|
|
|
|
|
|
+ $f3->set('USER', $loggedUser);
|
|
|
|
|
|
|
|
- $f3->set('USER', $loggedUser);
|
|
|
|
|
|
|
+ // Check if user has permissions to navigate in current url
|
|
|
|
|
+ $currentAlias = $f3->get('ALIAS');
|
|
|
|
|
|
|
|
- // Check if user has permissions to navigate in current url
|
|
|
|
|
- $currentAlias = $f3->get('ALIAS');
|
|
|
|
|
|
|
+ // If user is not logged and page require a permission, redirect to '/'
|
|
|
|
|
+ if (!$loggedUser && $currentAlias) {
|
|
|
|
|
+ $f3->reroute('/');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // If user is not logged and page require a permission, redirect to '/'
|
|
|
|
|
- if (!$loggedUser && $currentAlias) {
|
|
|
|
|
- $f3->reroute('/');
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ $loggedUser && // user is logged in?
|
|
|
|
|
+ $currentAlias && // the page require a permission?
|
|
|
|
|
+ !$loggedUser->hasPermission($currentAlias) // The user has the permission to go next step?
|
|
|
|
|
+ ) {
|
|
|
|
|
+ $f3->reroute('/homemenu');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (
|
|
|
|
|
- $loggedUser && // user is logged in?
|
|
|
|
|
- $currentAlias && // the page require a permission?
|
|
|
|
|
- !$loggedUser->hasPermission($currentAlias) // The user has the permission to go next step?
|
|
|
|
|
- ) {
|
|
|
|
|
- $f3->reroute('/homemenu');
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- public function __destruct()
|
|
|
|
|
|
|
+ public function __destruct()
|
|
|
{
|
|
{
|
|
|
global $f3, $frameworkUtils;
|
|
global $f3, $frameworkUtils;
|
|
|
if ($f3->get('DEBUG') > 2) {
|
|
if ($f3->get('DEBUG') > 2) {
|
|
@@ -66,26 +67,26 @@ class Controller
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Return the sanitized POST parameters
|
|
|
|
|
- *
|
|
|
|
|
- * @return mixed
|
|
|
|
|
- */
|
|
|
|
|
- protected function getSanitizedPostRequest()
|
|
|
|
|
- {
|
|
|
|
|
- return $this->sanitizedPostRequest;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Use setTimeout to request a change url
|
|
|
|
|
- *
|
|
|
|
|
- * @param string $url to change to
|
|
|
|
|
- * @param int $msDelay
|
|
|
|
|
- */
|
|
|
|
|
- protected function setRedirect(string $url, int $msDelay)
|
|
|
|
|
- {
|
|
|
|
|
- global $f3;
|
|
|
|
|
-
|
|
|
|
|
- $f3->set('REQ_REDIRECT', $url);
|
|
|
|
|
- $f3->set('REQ_REDIRECT_MS', $msDelay);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ * Return the sanitized POST parameters
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ */
|
|
|
|
|
+ protected function getSanitizedPostRequest()
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->sanitizedPostRequest;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Use setTimeout to request a change url
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param string $url to change to
|
|
|
|
|
+ * @param int $msDelay
|
|
|
|
|
+ */
|
|
|
|
|
+ protected function setRedirect(string $url, int $msDelay)
|
|
|
|
|
+ {
|
|
|
|
|
+ global $f3;
|
|
|
|
|
+
|
|
|
|
|
+ $f3->set('REQ_REDIRECT', $url);
|
|
|
|
|
+ $f3->set('REQ_REDIRECT_MS', $msDelay);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|