From 9e1a29a24b5e273389cdf3a7aa80aece10f43fa3 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Thu, 9 Apr 2020 17:47:44 +0200 Subject: [PATCH] FEAT #13441 TIME 0:45 Fixes --- migration/20.10/2010.sql | 2 + sql/structure.sql | 2 - .../controllers/TemplateController.php | 4 +- src/core/models/AuthenticationModel.php | 89 +------------------ 4 files changed, 5 insertions(+), 92 deletions(-) diff --git a/migration/20.10/2010.sql b/migration/20.10/2010.sql index 63df31d20fb..f43bf61c400 100755 --- a/migration/20.10/2010.sql +++ b/migration/20.10/2010.sql @@ -20,6 +20,8 @@ ALTER TABLE notif_email_stack DROP COLUMN IF EXISTS text_body; ALTER TABLE notif_email_stack DROP COLUMN IF EXISTS module; /* USERS */ +ALTER TABLE users DROP COLUMN IF EXISTS cookie_key; +ALTER TABLE users DROP COLUMN IF EXISTS cookie_date; ALTER TABLE users DROP COLUMN IF EXISTS refresh_token; ALTER TABLE users ADD COLUMN refresh_token jsonb NOT NULL DEFAULT '[]'; diff --git a/sql/structure.sql b/sql/structure.sql index 9642efd8ff5..e4798a6f9e8 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -220,8 +220,6 @@ CREATE TABLE users status character varying(10) NOT NULL DEFAULT 'OK'::character varying, password_modification_date timestamp without time zone DEFAULT CURRENT_TIMESTAMP, loginmode character varying(50) DEFAULT NULL::character varying, - cookie_key character varying(255) DEFAULT NULL::character varying, - cookie_date timestamp without time zone, refresh_token jsonb NOT NULL DEFAULT '[]', reset_token text, failed_authentication INTEGER DEFAULT 0, diff --git a/src/app/template/controllers/TemplateController.php b/src/app/template/controllers/TemplateController.php index f2629c25c50..bc73dc60e5a 100755 --- a/src/app/template/controllers/TemplateController.php +++ b/src/app/template/controllers/TemplateController.php @@ -113,8 +113,8 @@ class TemplateController return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); } - if ($body['target'] == 'acknowledgementReceipt' && !empty($data['entities'])) { - $checkEntities = TemplateModel::checkEntities(['data' => $data]); + if ($body['target'] == 'acknowledgementReceipt' && !empty($body['entities'])) { + $checkEntities = TemplateModel::checkEntities(['data' => $body]); if (!empty($checkEntities)) { return $response->withJson(['checkEntities' => $checkEntities]); } diff --git a/src/core/models/AuthenticationModel.php b/src/core/models/AuthenticationModel.php index 9986cd3c168..9939b840192 100755 --- a/src/core/models/AuthenticationModel.php +++ b/src/core/models/AuthenticationModel.php @@ -39,94 +39,7 @@ class AuthenticationModel return password_verify($args['password'], $aReturn[0]['password']); } - - public static function getCookieAuth() - { - $rawCookie = $_COOKIE['maarchCourrierAuth']; - if (empty($rawCookie)) { - return []; - } - - $cookieDecoded = base64_decode($rawCookie); - $cookie = json_decode($cookieDecoded); - - return (array)$cookie; - } - - public static function cookieAuthentication(array $args) - { - ValidatorModel::notEmpty($args, ['userId', 'cookieKey']); - ValidatorModel::stringType($args, ['userId', 'cookieKey']); - - $aReturn = DatabaseModel::select([ - 'select' => [1], - 'table' => ['users'], - 'where' => ['lower(user_id) = lower(?)', 'cookie_key = ?', 'cookie_date > CURRENT_TIMESTAMP'], - 'data' => [$args['userId'], $args['cookieKey']] - ]); - - if (empty($aReturn[0])) { - return false; - } - - return true; - } - - public static function setCookieAuth(array $args) - { - ValidatorModel::notEmpty($args, ['userId']); - ValidatorModel::stringType($args, ['userId']); - - $cookieTime = 0; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/config.xml']); - if ($loadedXml) { - $cookieTime = (string)$loadedXml->CONFIG->CookieTime; - } - - $user = DatabaseModel::select([ - 'select' => ['id', 'cookie_key'], - 'table' => ['users'], - 'where' => ['lower(user_id) = lower(?)', 'cookie_date > CURRENT_TIMESTAMP'], - 'data' => [$args['userId']] - ]); - if (empty($user[0]['cookie_key'])) { - $cookieKey = AuthenticationModel::getPasswordHash($args['userId']); - } else { - $cookieKey = $user[0]['cookie_key']; - } - - $cookiePath = str_replace(['apps/maarch_entreprise/index.php', 'apps/maarch_entreprise/log.php', 'rest/index.php'], '', $_SERVER['SCRIPT_NAME']); - $cookieTime = time() + 60 * $cookieTime; - - DatabaseModel::update([ - 'table' => 'users', - 'set' => [ - 'cookie_key' => $cookieKey, - 'cookie_date' => date('Y-m-d H:i:s', $cookieTime), - ], - 'where' => ['lower(user_id) = lower(?)'], - 'data' => [$args['userId']] - ]); - - $cookieData = json_encode(['id' => $user[0]['id'],'userId' => $args['userId'], 'cookieKey' => $cookieKey]); - setcookie('maarchCourrierAuth', base64_encode($cookieData), $cookieTime, $cookiePath, '', false, false); - - return true; - } - - public static function deleteCookieAuth() - { - $previousCookie = AuthenticationModel::getCookieAuth(); - - if (!empty($previousCookie)) { - $cookiePath = str_replace(['apps/maarch_entreprise/index.php', 'rest/index.php'], '', $_SERVER['SCRIPT_NAME']); - setcookie('maarchCourrierAuth', '', time() - 1, $cookiePath, '', false, true); - } - - return true; - } - + public static function resetFailedAuthentication(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['userId']); -- GitLab