From 45db7e7b937fadbcb6377ecd3e5e3bc99d907fce Mon Sep 17 00:00:00 2001 From: Christiaan Goossens Date: Sun, 26 Mar 2017 15:28:33 +0200 Subject: [PATCH] Added proper session handling while in development mode --- .gitignore | 1 + public/index.php | 9 +++++++-- src/Application/Auth/Authorization.php | 13 +++++++++---- src/bootstrap.php | 2 ++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index cd7aa82..6a6350a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /vendor/ /logs/* +/tmp/ diff --git a/public/index.php b/public/index.php index 49d2a47..dd821e3 100644 --- a/public/index.php +++ b/public/index.php @@ -12,8 +12,13 @@ * Jelmer Hinssen */ - // Create session - session_start(); +/** + * Session fix for development + */ + +if (session_save_path() === "") { + ini_set('session.save_path', realpath(__DIR__ . '/../tmp')); +} /** * Check if the script is running in CLI mode diff --git a/src/Application/Auth/Authorization.php b/src/Application/Auth/Authorization.php index 34b36d0..2c979fc 100644 --- a/src/Application/Auth/Authorization.php +++ b/src/Application/Auth/Authorization.php @@ -33,17 +33,22 @@ class Authorization $klantnr = $rekeningen[$id]['klantid']; $klant = $db->klanten->where('id', $klantnr)[$klantnr]; - if ($klant['code'] === $passcode) { - $_SESSION['user'] = $klant; + if ($klant['code'] === $passcode) { + $_SESSION['userid'] = $klant['id']; return true; } return false; } - public function getUser() + public function getUserID() + { + return $_SESSION['userid']; + } + + public function isUserAuthenticated() { - return $_SESSION['user']; + return $this->getUserID() !== null; } } diff --git a/src/bootstrap.php b/src/bootstrap.php index ae25891..fee2e5a 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -16,6 +16,8 @@ * BOOTSTRAPPING SCRIPT */ +session_start(); + // Get the Slim framework settings $settings = require __DIR__ . '/settings.php';