Régénere la session à l'installation et au login

This commit is contained in:
Fred Tempez 2023-04-23 07:39:40 +02:00
parent 28e8af3f1f
commit 5fdb0c8ff5
2 changed files with 44 additions and 31 deletions

View File

@ -50,7 +50,9 @@ class install extends common
'access' => false 'access' => false
]); ]);
} }
// Accès autorisé
// Soumission du formulaire // Soumission du formulaire
if ($this->isPost()) { if ($this->isPost()) {
$lang = $this->getInput('installLanguage'); $lang = $this->getInput('installLanguage');
@ -64,6 +66,9 @@ class install extends common
]); ]);
} }
// Régénère la session
session_regenerate_id();
// Liste des langues UI disponibles // Liste des langues UI disponibles
if (is_dir(self::I18N_DIR)) { if (is_dir(self::I18N_DIR)) {
foreach ($this->getData(['languages']) as $lang => $value) { foreach ($this->getData(['languages']) as $lang => $value) {

View File

@ -105,9 +105,9 @@ class user extends common
$userMail, $userMail,
'Compte créé sur ' . $this->getData(['locale', 'title']), 'Compte créé sur ' . $this->getData(['locale', 'title']),
'Bonjour <strong>' . $userFirstname . ' ' . $userLastname . '</strong>,<br><br>' . 'Bonjour <strong>' . $userFirstname . ' ' . $userLastname . '</strong>,<br><br>' .
'Un administrateur vous a créé un compte sur le site ' . $this->getData(['locale', 'title']) . '. Vous trouverez ci-dessous les détails de votre compte.<br><br>' . 'Un administrateur vous a créé un compte sur le site ' . $this->getData(['locale', 'title']) . '. Vous trouverez ci-dessous les détails de votre compte.<br><br>' .
'<strong>Identifiant du compte :</strong> ' . $this->getInput('userAddId') . '<br>' . '<strong>Identifiant du compte :</strong> ' . $this->getInput('userAddId') . '<br>' .
'<small>Nous ne conservons pas les mots de passe, en conséquence nous vous conseillons de conserver ce message tant que vous ne vous êtes pas connecté. Vous pourrez modifier votre mot de passe après votre première connexion.</small>', '<small>Nous ne conservons pas les mots de passe, en conséquence nous vous conseillons de conserver ce message tant que vous ne vous êtes pas connecté. Vous pourrez modifier votre mot de passe après votre première connexion.</small>',
null, null,
$this->getData(['config', 'smtp', 'from']), $this->getData(['config', 'smtp', 'from']),
); );
@ -205,7 +205,7 @@ class user extends common
$this->getData(['user', $this->getUrl(2)]) === null $this->getData(['user', $this->getUrl(2)]) === null
// Droit d'édition // Droit d'édition
and ( and (
// Impossible de s'auto-éditer // Impossible de s'auto-éditer
($this->getUser('id') === $this->getUrl(2) ($this->getUser('id') === $this->getUrl(2)
and $this->getUrl('group') <= self::GROUP_VISITOR and $this->getUrl('group') <= self::GROUP_VISITOR
) )
@ -306,7 +306,7 @@ class user extends common
foreach (self::$languagesInstalled as $lang => $datas) { foreach (self::$languagesInstalled as $lang => $datas) {
self::$languagesInstalled[$lang] = self::$languages[$lang]; self::$languagesInstalled[$lang] = self::$languages[$lang];
} }
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'title' => $this->getData(['user', $this->getUrl(2), 'firstname']) . ' ' . $this->getData(['user', $this->getUrl(2), 'lastname']), 'title' => $this->getData(['user', $this->getUrl(2), 'firstname']) . ' ' . $this->getData(['user', $this->getUrl(2), 'lastname']),
@ -333,9 +333,9 @@ class user extends common
$this->getData(['user', $userId, 'mail']), $this->getData(['user', $userId, 'mail']),
'Réinitialisation de votre mot de passe', 'Réinitialisation de votre mot de passe',
'Bonjour <strong>' . $this->getData(['user', $userId, 'firstname']) . ' ' . $this->getData(['user', $userId, 'lastname']) . '</strong>,<br><br>' . 'Bonjour <strong>' . $this->getData(['user', $userId, 'firstname']) . ' ' . $this->getData(['user', $userId, 'lastname']) . '</strong>,<br><br>' .
'Vous avez demandé à changer le mot de passe lié à votre compte. Vous trouverez ci-dessous un lien vous permettant de modifier celui-ci.<br><br>' . 'Vous avez demandé à changer le mot de passe lié à votre compte. Vous trouverez ci-dessous un lien vous permettant de modifier celui-ci.<br><br>' .
'<a href="' . helper::baseUrl() . 'user/reset/' . $userId . '/' . $uniqId . '" target="_blank">' . helper::baseUrl() . 'user/reset/' . $userId . '/' . $uniqId . '</a><br><br>' . '<a href="' . helper::baseUrl() . 'user/reset/' . $userId . '/' . $uniqId . '" target="_blank">' . helper::baseUrl() . 'user/reset/' . $userId . '/' . $uniqId . '</a><br><br>' .
'<small>Si nous n\'avez pas demandé à réinitialiser votre mot de passe, veuillez ignorer ce mail.</small>', '<small>Si nous n\'avez pas demandé à réinitialiser votre mot de passe, veuillez ignorer ce mail.</small>',
null, null,
$this->getData(['config', 'smtp', 'from']), $this->getData(['config', 'smtp', 'from']),
); );
@ -349,7 +349,7 @@ class user extends common
else { else {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'notification' => helper::translate('Utilisateur inexistant') 'notification' => helper::translate('Utilisateur inexistant')
]); ]);
} }
} }
@ -454,7 +454,7 @@ class user extends common
} else { } else {
// Cas 4 : le délai de blocage est dépassé et le compte est au max - Réinitialiser // Cas 4 : le délai de blocage est dépassé et le compte est au max - Réinitialiser
if ( if (
$this->getData(['user', $userId, 'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time() $this->getData(['user', $userId, 'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time()
and $this->getData(['user', $userId, 'connectFail']) === $this->getData(['config', 'connect', 'attempt']) and $this->getData(['user', $userId, 'connectFail']) === $this->getData(['config', 'connect', 'attempt'])
) { ) {
$this->setData(['user', $userId, 'connectFail', 0]); $this->setData(['user', $userId, 'connectFail', 0]);
@ -510,8 +510,8 @@ class user extends common
$this->setData(['user', $userId, 'connectTimeout', time()]); $this->setData(['user', $userId, 'connectTimeout', time()]);
} }
// Cas 3 le délai de bloquage court // Cas 3 le délai de bloquage court
if ($this->getData(['user', $userId, 'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) > time()) { if ($this->getData(['user', $userId, 'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) > time()) {
$notification = sprintf(helper::translate('Accès bloqué %d minutes'), ($this->getData(['config', 'connect', 'timeout']) / 60)); $notification = sprintf(helper::translate('Accès bloqué %d minutes'), ($this->getData(['config', 'connect', 'timeout']) / 60));
} }
// Valeurs en sortie // Valeurs en sortie
@ -524,13 +524,17 @@ class user extends common
// Journalisation // Journalisation
$dataLog = helper::dateUTF8('%Y %m %d', time()) . ' - ' . helper::dateUTF8('%H:%M', time()); $dataLog = helper::dateUTF8('%Y %m %d', time()) . ' - ' . helper::dateUTF8('%H:%M', time());
$dataLog .= helper::getIp($this->getData(['config', 'connect', 'anonymousIp'])) . ';'; $dataLog .= helper::getIp($this->getData(['config', 'connect', 'anonymousIp'])) . ';';
$dataLog .= empty($this->getInput('userLoginId')) ? ';' : $this->getInput('userLoginId', helper::FILTER_ID) . ';'; $dataLog .= empty($this->getInput('userLoginId')) ? ';' : $this->getInput('userLoginId', helper::FILTER_ID) . ';';
$dataLog .= $this->getUrl() . ';'; $dataLog .= $this->getUrl() . ';';
$dataLog .= $logStatus; $dataLog .= $logStatus;
$dataLog .= PHP_EOL; $dataLog .= PHP_EOL;
if ($this->getData(['config', 'connect', 'log'])) { if ($this->getData(['config', 'connect', 'log'])) {
file_put_contents(self::DATA_DIR . 'journal.log', $dataLog, FILE_APPEND); file_put_contents(self::DATA_DIR . 'journal.log', $dataLog, FILE_APPEND);
} }
// Régénère la session
session_regenerate_id();
// Stockage des cookies // Stockage des cookies
if (!empty($_COOKIE['ZWII_USER_ID'])) { if (!empty($_COOKIE['ZWII_USER_ID'])) {
self::$userId = $_COOKIE['ZWII_USER_ID']; self::$userId = $_COOKIE['ZWII_USER_ID'];
@ -631,11 +635,11 @@ class user extends common
$filePath = self::FILE_DIR . 'source/' . $file; $filePath = self::FILE_DIR . 'source/' . $file;
if ($file and file_exists($filePath)) { if ($file and file_exists($filePath)) {
// Analyse et extraction du CSV // Analyse et extraction du CSV
$rows = array_map(function ($row) { $rows = array_map(function ($row) {
return str_getcsv($row, $this->getInput('userImportSeparator')); return str_getcsv($row, $this->getInput('userImportSeparator'));
}, file($filePath)); }, file($filePath));
$header = array_shift($rows); $header = array_shift($rows);
$csv = array(); $csv = array();
foreach ($rows as $row) { foreach ($rows as $row) {
$csv[] = array_combine($header, $row); $csv[] = array_combine($header, $row);
} }
@ -656,7 +660,7 @@ class user extends common
) { ) {
// Validation du groupe // Validation du groupe
$item['groupe'] = (int) $item['groupe']; $item['groupe'] = (int) $item['groupe'];
$item['groupe'] = ($item['groupe'] >= self::GROUP_BANNED and $item['groupe'] <= self::GROUP_ADMIN) $item['groupe'] = ($item['groupe'] >= self::GROUP_BANNED and $item['groupe'] <= self::GROUP_ADMIN)
? $item['groupe'] : 1; ? $item['groupe'] : 1;
// L'utilisateur existe // L'utilisateur existe
if ($this->getData(['user', helper::filter($item['id'], helper::FILTER_ID)])) { if ($this->getData(['user', helper::filter($item['id'], helper::FILTER_ID)])) {
@ -679,15 +683,18 @@ class user extends common
// Enregistre le user // Enregistre le user
$create = $this->setData([ $create = $this->setData([
'user', 'user',
$userId, [ $userId,
[
'firstname' => $item['prenom'], 'firstname' => $item['prenom'],
'forgot' => 0, 'forgot' => 0,
'group' => $item['groupe'], 'group' => $item['groupe'],
'lastname' => $item['nom'], 'lastname' => $item['nom'],
'mail' => $item['email'], 'mail' => $item['email'],
'pseudo' => $item['prenom'], 'pseudo' => $item['prenom'],
'signature' => 1, // Pseudo 'signature' => 1,
'password' => uniqid(), // A modifier à la première connexion // Pseudo
'password' => uniqid(),
// A modifier à la première connexion
"connectFail" => null, "connectFail" => null,
"connectTimeout" => null, "connectTimeout" => null,
"accessUrl" => null, "accessUrl" => null,
@ -696,7 +703,7 @@ class user extends common
] ]
]); ]);
// Icône de notification // Icône de notification
$item['notification'] = $create ? template::ico('check') : template::ico('cancel'); $item['notification'] = $create ? template::ico('check') : template::ico('cancel');
// Envoi du mail // Envoi du mail
if ( if (
$create $create
@ -706,11 +713,11 @@ class user extends common
$item['email'], $item['email'],
'Compte créé sur ' . $this->getData(['locale', 'title']), 'Compte créé sur ' . $this->getData(['locale', 'title']),
'Bonjour <strong>' . $item['prenom'] . ' ' . $item['nom'] . '</strong>,<br><br>' . 'Bonjour <strong>' . $item['prenom'] . ' ' . $item['nom'] . '</strong>,<br><br>' .
'Un administrateur vous a créé un compte sur le site ' . $this->getData(['locale', 'title']) . '. Vous trouverez ci-dessous les détails de votre compte.<br><br>' . 'Un administrateur vous a créé un compte sur le site ' . $this->getData(['locale', 'title']) . '. Vous trouverez ci-dessous les détails de votre compte.<br><br>' .
'<strong>Identifiant du compte :</strong> ' . $userId . '<br>' . '<strong>Identifiant du compte :</strong> ' . $userId . '<br>' .
'<small>Un mot de passe provisoire vous été attribué, à la première connexion cliquez sur Mot de passe Oublié.</small>', '<small>Un mot de passe provisoire vous été attribué, à la première connexion cliquez sur Mot de passe Oublié.</small>',
null, null,
$this->getData(['config', 'smtp', 'from']), $this->getData(['config', 'smtp', 'from']),
); );
if ($sent === true) { if ($sent === true) {
// Mail envoyé changement de l'icône // Mail envoyé changement de l'icône
@ -731,10 +738,10 @@ class user extends common
} }
} }
if (empty(self::$users)) { if (empty(self::$users)) {
$notification = helper::translate('Rien à importer, erreur de format ou fichier incorrect'); $notification = helper::translate('Rien à importer, erreur de format ou fichier incorrect');
$success = false; $success = false;
} else { } else {
$notification = helper::translate('Importation effectuée'); $notification = helper::translate('Importation effectuée');
$success = true; $success = true;
} }
} else { } else {
@ -753,8 +760,9 @@ class user extends common
/** /**
* Télécharge un modèle * Télécharge un modèle
*/ */
public function template() { public function template()
{
$file = 'template.csv'; $file = 'template.csv';
$path = 'core/module/user/ressource/'; $path = 'core/module/user/ressource/';
// Téléchargement du CSV // Téléchargement du CSV
@ -766,4 +774,4 @@ class user extends common
readfile($path . $file); readfile($path . $file);
exit(); exit();
} }
} }