Skip to content
Snippets Groups Projects
Verified Commit c40051ed authored by Damien's avatar Damien
Browse files

[REFACTORING] Routes without auth

parent 70513684
No related branches found
No related tags found
No related merge requests found
......@@ -28,32 +28,28 @@ require_once("src/core/lang/lang-{$language}.php");
$app = new \Slim\App(['settings' => ['displayErrorDetails' => true, 'determineRouteBeforeAppMiddleware' => true]]);
//route without auth
$app->get('/jnlpDownload/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':donwloadJnlp');
//Authentication
$app->add(function (\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next) {
$routesWithoutAuthentication = ['/jnlpDownload/{jnlpUniqueId}'];
$route = $request->getAttribute('route');
if ($route->getPattern() <> '/jnlpDownload/{jnlpUniqueId}') {
$currentRoute = empty($route) ? '' : $route->getPattern();
if (!in_array($currentRoute, $routesWithoutAuthentication)) {
$userId = \SrcCore\controllers\AuthenticationController::authentication();
if (!empty($userId)) {
$GLOBALS['userId'] = $userId;
if (!empty($route)) {
$currentRoute = $route->getPattern();
if (!empty($currentRoute)) {
$r = \SrcCore\controllers\AuthenticationController::isRouteAvailable(['userId' => $userId, 'currentRoute' => $currentRoute]);
if (!$r['isRouteAvailable']) {
return $response->withStatus(405)->withJson(['errors' => $r['errors']]);
}
}
$response = $next($request, $response);
return $response;
} else {
return $response->withStatus(401)->withJson(['errors' => 'Authentication Failed']);
}
} else {
$response = $next($request, $response);
return $response;
}
$response = $next($request, $response);
return $response;
});
//Initialize
......@@ -177,8 +173,8 @@ $app->get('/home/lastRessources', \Home\controllers\HomeController::class . ':ge
//Jnlp
$app->post('/jnlp', \ContentManagement\controllers\JnlpController::class . ':generateJnlp');
//$app->get('/jnlp/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':renderJnlp');
$app->get('/jnlpDownload/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':donwloadJnlp');
$app->get('/jnlp/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':renderJnlp');
$app->post('/jnlp/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':processJnlp');
$app->get('/jnlp/lock/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':isLockFileExisting');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment