This commit is contained in:
Yuri Kuznetsov
2020-09-25 13:21:02 +03:00
parent bcbb29d94e
commit dec5e0be5f
3 changed files with 26 additions and 2 deletions
@@ -105,13 +105,16 @@ class EntryPoint implements ApplicationRunner
if ($authRequired && !$authNotStrict && !$final) {
$portalId = $this->detectPortalId();
if ($portalId) {
$this->runThroughPortal($portalId, $entryPoint, $data);
return;
}
}
$slim = SlimAppFactory::create();
$slim->setBasePath(Route::detectBasePath());
$slim->add(
@@ -164,7 +167,9 @@ class EntryPoint implements ApplicationRunner
}
ob_start();
$this->entryPointManager->run($entryPoint, $requestWrapped, $responseWrapped, $data);
$contents = ob_get_clean();
if ($contents) {
@@ -180,20 +185,27 @@ class EntryPoint implements ApplicationRunner
if (!empty($_GET['portalId'])) {
return $_GET['portalId'];
}
if (!empty($_COOKIE['auth-token'])) {
$token = $this->entityManager->getRepository('AuthToken')->where(['token' => $_COOKIE['auth-token']])->findOne();
$token = $this->entityManager
->getRepository('AuthToken')
->where(['token' => $_COOKIE['auth-token']])
->findOne();
if ($token && $token->get('portalId')) {
return $token->get('portalId');
}
}
return null;
}
protected function runThroughPortal(string $portalId, string $entryPoint, ?StdClass $data)
{
$app = new PortalApplication($portalId);
$app->setClientBasePath($this->clientManager->getBasePath());
$app->run(EntryPoint::class, (object) [
'entryPoint' => $entryPoint,
'data' => $data,
+5
View File
@@ -68,23 +68,28 @@ class Portal implements EntryPoint
if (!$id) {
$url = $_SERVER['REQUEST_URI'];
$id = explode('/', $url)[count(explode('/', $_SERVER['SCRIPT_NAME'])) - 1];
if (!isset($id)) {
$url = $_SERVER['REDIRECT_URL'];
$id = explode('/', $url)[count(explode('/', $_SERVER['SCRIPT_NAME'])) - 1];
}
if (!$id) {
$id = $this->config->get('defaultPortalId');
}
if (!$id) {
throw new NotFound();
}
}
$application = new PortalApplication($id);
$application->setClientBasePath($this->clientManager->getBasePath());
$application->run(Client::class);
}
}
+8 -1
View File
@@ -50,20 +50,26 @@ if (strpos($requestUri, '=') !== false) {
if (!isset($portalId)) {
$url = $_SERVER['REDIRECT_URL'];
$portalId = explode('/', $url)[count(explode('/', $_SERVER['SCRIPT_NAME'])) - 1];
}
$a = explode('?', $url);
if (substr($a[0], -1) !== '/') {
$url = $a[0] . '/';
if (count($a) > 1) {
$url .= '?' . $a[1];
}
header("Location: " . $url);
exit();
exit;
}
$a = explode('?', $requestUri);
$requestUri = rtrim($a[0], '/');
if (strpos($requestUri, '/') !== false) {
@@ -76,6 +82,7 @@ if (strpos($requestUri, '/') !== false) {
if (!empty($_GET['entryPoint'])) {
$app->run(EntryPoint::class);
exit;
}