Skip to content
Snippets Groups Projects
Verified Commit 7a708bb7 authored by Damien's avatar Damien
Browse files

[REFACTORING] Authentication

parent 3bf40468
No related branches found
No related tags found
No related merge requests found
......@@ -360,8 +360,7 @@ if (file_exists($path)) {
if ($core->is_module_loaded('basket')
&& isset($_SESSION['abs_user_status'])
&& $_SESSION['abs_user_status'] == true) {
include
'modules/basket/advert_missing.php';
include 'modules/basket/advert_missing.php';
} elseif (empty($_REQUEST['triggerAngular'])) {
$core->insert_page();
}
......
......@@ -30,18 +30,7 @@ $app = new \Slim\App(['settings' => ['displayErrorDetails' => true, 'determineRo
//Authentication
$app->add(function (\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next) {
$userId = null;
if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
if (\SrcCore\models\AuthenticationModel::authentication(['userId' => $_SERVER['PHP_AUTH_USER'], 'password' => $_SERVER['PHP_AUTH_PW']])) {
$userId = $_SERVER['PHP_AUTH_USER'];
}
} else {
$cookie = \SrcCore\models\SecurityModel::getCookieAuth();
if (!empty($cookie) && \SrcCore\models\SecurityModel::cookieAuthentication($cookie)) {
\SrcCore\models\SecurityModel::setCookieAuth(['userId' => $cookie['userId']]);
$userId = $cookie['userId'];
}
}
$userId = \SrcCore\controllers\AuthenticationController::authentication();
if (!empty($userId)) {
$GLOBALS['userId'] = $userId;
......
......@@ -16,11 +16,30 @@ namespace SrcCore\controllers;
use SrcCore\models\AuthenticationModel;
use SrcCore\models\PasswordModel;
use SrcCore\models\SecurityModel;
use SrcCore\models\ValidatorModel;
use User\models\UserModel;
class AuthenticationController
{
public static function authentication()
{
$userId = null;
if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
if (AuthenticationModel::authentication(['userId' => $_SERVER['PHP_AUTH_USER'], 'password' => $_SERVER['PHP_AUTH_PW']])) {
$userId = $_SERVER['PHP_AUTH_USER'];
}
} else {
$cookie = SecurityModel::getCookieAuth();
if (!empty($cookie) && SecurityModel::cookieAuthentication($cookie)) {
SecurityModel::setCookieAuth(['userId' => $cookie['userId']]);
$userId = $cookie['userId'];
}
}
return $userId;
}
public static function handleFailedAuthentication(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['userId']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment