Added redirects and middleware classes for login
parent
40d3ec9052
commit
014adeed65
@ -1,18 +0,0 @@
|
||||
body {
|
||||
margin: 50px 0 0 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
text-align: center;
|
||||
color: #aaa;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #719e40;
|
||||
letter-spacing: -3px;
|
||||
font-family: 'Lato', sans-serif;
|
||||
font-size: 100px;
|
||||
font-weight: 200;
|
||||
margin-bottom: 0;
|
||||
}
|
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Informatica Eindproject D4p
|
||||
* 6in3, Stedelijk Gymnasium Nijmegen
|
||||
* Docent: Hans de Wolf
|
||||
*
|
||||
* ==================
|
||||
*
|
||||
* Daniel Boutros,
|
||||
* Christiaan Goossens,
|
||||
* Jelmer Hinssen
|
||||
*/
|
||||
|
||||
namespace Inforbank\Application\Helper;
|
||||
|
||||
class Redirect
|
||||
{
|
||||
public static function create($response, $path)
|
||||
{
|
||||
$response = $response->withStatus(302);
|
||||
$response = $response->withHeader('Location', Redirect::getBasepath() . $path);
|
||||
return $response;
|
||||
}
|
||||
|
||||
private static function getBasepath()
|
||||
{
|
||||
if (isset($_SERVER['HTTPS'])) {
|
||||
$protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http";
|
||||
} else {
|
||||
$protocol = 'http';
|
||||
}
|
||||
return $protocol . "://" . $_SERVER['HTTP_HOST'];
|
||||
}
|
||||
}
|
Reference in New Issue