Added redirects and middleware classes for login
This commit is contained in:
34
src/Application/Auth/Middleware.php
Normal file
34
src/Application/Auth/Middleware.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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
|
||||
{
|
||||
public function __invoke($request, $response, $next)
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
|
||||
// Check for an existing session
|
||||
if ($container->auth->isUserAuthenticated()) {
|
||||
return $next($request, $response);
|
||||
} else {
|
||||
// Redirect to the login page
|
||||
return Redirect::create($response, '/login');
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user