[add] Setting up the middleware

This commit is contained in:
2018-08-15 23:41:01 -06:00
parent 86a0540da7
commit df33525a4b
7 changed files with 189 additions and 12 deletions

View File

@@ -4,11 +4,13 @@ namespace App\Application;
use Exception;
class SessionApplication{
private $session;
private $pdo;
private $cryptographyService;
private $asserts;
function __construct($mysql, $cryptographyService, $asserts){
function __construct($session, $mysql, $cryptographyService, $asserts){
$this->session = $session;
$this->cryptographyService = $cryptographyService;
$this->pdo = $mysql;
$this->asserts = $asserts;
@@ -18,7 +20,8 @@ class SessionApplication{
* @return bool
*/
function verifySession(){
return isset($_SESSION['userName']);
$userName = $this->session->get('userName');
return isset($userName);
}
/**
@@ -30,7 +33,7 @@ class SessionApplication{
$session['loggedIn'] = $this->verifySession();
if($this->verifySession()){
$session['userName'] = $_SESSION['userName'];
$session['userName'] = $this->session->get('userName');
}
return $session;
@@ -83,7 +86,7 @@ class SessionApplication{
}
if($this->cryptographyService->decryptPassword($password, $storedPassword)){
$_SESSION['userName'] = $userName;
$this->session->set('userName', $userName);
return true;
}
else{
@@ -118,7 +121,7 @@ class SessionApplication{
* @return array
*/
function destroySession(){
session_destroy();
$this->session->clear();
return array('status' => 'success', 'message' => 'Successfully logged out.');
}