diff --git a/public/assets/css/demo.css b/public/assets/css/demo.css deleted file mode 100644 index 322b3bf..0000000 --- a/public/assets/css/demo.css +++ /dev/null @@ -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; -} diff --git a/src/Application/Auth/Authorization.php b/src/Application/Auth/Authorization.php index 2c979fc..65ab98a 100644 --- a/src/Application/Auth/Authorization.php +++ b/src/Application/Auth/Authorization.php @@ -51,4 +51,9 @@ class Authorization { return $this->getUserID() !== null; } + + public function logout() + { + unset($_SESSION['userid']); + } } diff --git a/src/Application/Auth/Middleware.php b/src/Application/Auth/Middleware.php new file mode 100644 index 0000000..e578d91 --- /dev/null +++ b/src/Application/Auth/Middleware.php @@ -0,0 +1,34 @@ +auth->isUserAuthenticated()) { + return $next($request, $response); + } else { + // Redirect to the login page + return Redirect::create($response, '/login'); + } + } +} diff --git a/src/Application/Helper/Redirect.php b/src/Application/Helper/Redirect.php new file mode 100644 index 0000000..ed1ab63 --- /dev/null +++ b/src/Application/Helper/Redirect.php @@ -0,0 +1,35 @@ +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']; + } +} diff --git a/src/Application/Login.php b/src/Application/Login.php index f5a1e42..33da093 100644 --- a/src/Application/Login.php +++ b/src/Application/Login.php @@ -15,6 +15,7 @@ namespace Inforbank\Application; use \Slim\App; +use Inforbank\Application\Helper\Redirect; class Login { @@ -24,6 +25,7 @@ class Login // Render index view return $this->renderer->render($response, 'login.phtml', $args); }); + $app->post('/login', function ($request, $response, $args) { // Render index view $post = $request->getParsedBody(); @@ -32,15 +34,18 @@ class Login $resp = $this->auth->login($post['rekeningnr'], $post['pascode']); if ($resp) { - echo "HIER EEN REDIRECT GRAAG"; + return Redirect::create($response, '/'); } else { - echo "ERR PASS!"; + return Redirect::create($response, '/login?error'); } } catch (\Exception $e) { - echo "ERR REK!"; + return Redirect::create($response, '/login?error'); } + }); - die(); + $app->get('/logout', function ($request, $response, $args) { + $this->auth->logout(); + return Redirect::create($response, '/login'); }); } } diff --git a/src/Application/Main.php b/src/Application/Main.php index c48a78b..50965bd 100644 --- a/src/Application/Main.php +++ b/src/Application/Main.php @@ -32,9 +32,9 @@ class Main public function __construct(App $app) { // Add the default view routes - $app->get('/[{name}]', function ($request, $response, $args) { + $app->get('/', function ($request, $response, $args) { // Render index view return $this->renderer->render($response, 'index.phtml', $args); - }); + })->add(new Auth\Middleware()); } } diff --git a/templates/index.phtml b/templates/index.phtml index a09481c..358d6ce 100644 --- a/templates/index.phtml +++ b/templates/index.phtml @@ -2,18 +2,10 @@
-Try SlimFramework - +
Welkom klant = $_SESSION['userid'] ?>
+ Uitloggen