1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

53 lines
1.3 KiB
PHP

<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application\Auth;
use Inforbank\Application;
use Inforbank\Application\Helper\Redirect;
class Middleware
{
/**
* Middleware (https://www.slimframework.com/docs/concepts/middleware.html) om te checken of de gebruiker is ingelogd
*/
public function __invoke($request, $response, $next)
{
$container = Application::getContainer();
$uri = $request->getUri();
$path = $uri->getPath();
if (substr($path, 0, 1) != '/') {
$path = "/".$path;
}
$query = $uri->getQuery();
// Check for an existing session
if ($container->auth->isUserAuthenticated()) {
return $next($request, $response);
} else {
// Redirect to the login page
if ($query !== "") {
return Redirect::create($request, $response, '/login?redirect='.$path."&".$query);
} elseif ($path === "/") {
return Redirect::create($request, $response, '/login');
} else {
return Redirect::create($request, $response, '/login?redirect='.$path);
}
}
}
}