[add] In system validation for session

This commit is contained in:
Jose Pabl Domingo Aramburo Sanchez 2018-08-16 01:18:44 -06:00
parent e490f6aed1
commit a05a602954
7 changed files with 36 additions and 28 deletions

View File

@ -1,12 +1,3 @@
<?php
session_start();
if(!isset($_SESSION['userName'])){
header("Location: ./login.php");
exit();
}
?>
<!-- Latest compiled and minified CSS --> <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="../css/bootstrap.min.css"> <link rel="stylesheet" href="../css/bootstrap.min.css">
@ -40,10 +31,6 @@ if(!isset($_SESSION['userName'])){
<li> <li>
<a href="#" data-nav_accion="registerWorkDays.php" ><span class="glyphicon glyphicon-tasks"></span> Management</a> <a href="#" data-nav_accion="registerWorkDays.php" ><span class="glyphicon glyphicon-tasks"></span> Management</a>
</li> </li>
<li>
<a href="#" onclick="loadView();"><span class="glyphicon glyphicon-wrench"></span> Change password</a>
</li>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li> <li>

View File

@ -1,12 +1,3 @@
<?php
session_start();
if(isset($_SESSION['userName'])){
header("Location: ./landing.php");
exit();
}
?>
<!-- Latest compiled and minified CSS --> <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="../css/bootstrap.min.css"> <link rel="stylesheet" href="../css/bootstrap.min.css">

View File

@ -13,12 +13,15 @@ function logout() {
window.location.replace(baseUrl + '/html/login.php'); window.location.replace(baseUrl + '/html/login.php');
}, },
error:function(x,e) { error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) { if (x.status==0) {
$('#modalErrorInternetConnection').modal('show'); $('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) { } else if(x.status==404) {
$('#modalError404').modal('show'); $('#modalError404').modal('show');
} else if(x.status==500) { } else if(x.status==500) {
$('#modalError500').modal('show'); $('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') { } else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show'); $('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){ } else if(e=='timeout'){
@ -59,12 +62,15 @@ function loadView(requestedView){
$("#newViewBody").hide().html(data).show('slow'); $("#newViewBody").hide().html(data).show('slow');
}, },
error:function(x,e) { error:function(x,e) {
let responseText = $.parseJSON(x["responseText"]);
if (x.status==0) { if (x.status==0) {
$('#modalErrorInternetConnection').modal('show'); $('#modalErrorInternetConnection').modal('show');
} else if(x.status==404) { } else if(x.status==404) {
$('#modalError404').modal('show'); $('#modalError404').modal('show');
} else if(x.status==500) { } else if(x.status==500) {
$('#modalError500').modal('show'); $('#modalServerResponseError').modal('show');
document.getElementById('modalResponseError').innerHTML = responseText['message'];
} else if(e=='parsererror') { } else if(e=='parsererror') {
$('#modalErrorParsererror').modal('show'); $('#modalErrorParsererror').modal('show');
} else if(e=='timeout'){ } else if(e=='timeout'){

View File

@ -9,13 +9,28 @@ class EmployeeApplication{
private $cryptographyService; private $cryptographyService;
private $asserts; private $asserts;
private $settings; private $settings;
private $session;
function __construct($employeeSettings, $mysql, $cryptographyService, $asserts){ /**
* EmployeeApplication constructor.
* @param $employeeSettings
* @param $mysql
* @param $cryptographyService
* @param $asserts
* @param $session
* @throws Exception
*/
function __construct($employeeSettings, $mysql, $cryptographyService, $asserts, $session){
$this->settings = $employeeSettings; $this->settings = $employeeSettings;
$this->cryptographyService = $cryptographyService; $this->cryptographyService = $cryptographyService;
$this->pdo = $mysql; $this->pdo = $mysql;
$this->asserts = $asserts; $this->asserts = $asserts;
$this->session = $session;
if(!$this->session->verifySession()){
throw new Exception('A session is requited to access this resouerce.');
};
} }
/** /**
@ -81,7 +96,6 @@ class EmployeeApplication{
} catch( PDOExecption $e ) { } catch( PDOExecption $e ) {
$this->pdo->rollback(); $this->pdo->rollback();
throw new Exception('There was an error while trying to save a new person.'); throw new Exception('There was an error while trying to save a new person.');
$this->logger->warning("There was an error in the EmployeeApplication->saveNewPerson caused by: $e ");
} }
} }

View File

@ -87,6 +87,11 @@ class SessionApplication{
if($this->cryptographyService->decryptPassword($password, $storedPassword)){ if($this->cryptographyService->decryptPassword($password, $storedPassword)){
$this->session->set('userName', $userName); $this->session->set('userName', $userName);
if(!$this->verifySession()){
throw new Exception('An error occurred while trying to create the session.');
}
return true; return true;
} }
else{ else{
@ -119,10 +124,15 @@ class SessionApplication{
/** /**
* @return array * @return array
* @throws Exception
*/ */
function destroySession(){ function destroySession(){
$this->session->clear(); $this->session->clear();
if($this->verifySession()){
throw new Exception('An error occurred while trying to end the session.');
}
return array('status' => 'success', 'message' => 'Successfully logged out.'); return array('status' => 'success', 'message' => 'Successfully logged out.');
} }
} }

View File

@ -76,6 +76,6 @@ $container['sessionApplication'] = function ($c) {
$container['employeeApplication'] = function ($c) { $container['employeeApplication'] = function ($c) {
$employeeSettings = $c->get('settings')['employee']; $employeeSettings = $c->get('settings')['employee'];
$employeeApplication = new App\Application\EmployeeApplication($employeeSettings, $employeeApplication = new App\Application\EmployeeApplication($employeeSettings,
$c['mysql'], $c['cryptographyService'], $c['asserts']); $c['mysql'], $c['cryptographyService'], $c['asserts'], $c['sessionApplication']);
return $employeeApplication; return $employeeApplication;
}; };

View File

@ -22,7 +22,7 @@ return [
'name' => 'payroll-laziness-rocks', 'name' => 'payroll-laziness-rocks',
'lifetime' => 10, 'lifetime' => 10,
'path' => '/', 'path' => '/',
'domain' => "laziness.rocks", 'domain' => null,
'secure' => false, 'secure' => false,
'httponly' => true, 'httponly' => true,