param null login

This commit is contained in:
Fred Tempez 2022-10-05 18:16:49 +02:00
parent b0fec2951a
commit 1cf62d4140
1 changed files with 168 additions and 150 deletions

View File

@ -13,7 +13,8 @@
* @link http://zwiicms.fr/ * @link http://zwiicms.fr/
*/ */
class user extends common { class user extends common
{
public static $actions = [ public static $actions = [
'add' => self::GROUP_ADMIN, 'add' => self::GROUP_ADMIN,
@ -50,18 +51,19 @@ class user extends common {
/** /**
* Ajout * Ajout
*/ */
public function add() { public function add()
{
// Soumission du formulaire // Soumission du formulaire
if($this->isPost()) { if ($this->isPost()) {
$check=true; $check = true;
// L'identifiant d'utilisateur est indisponible // L'identifiant d'utilisateur est indisponible
$userId = $this->getInput('userAddId', helper::FILTER_ID, true); $userId = $this->getInput('userAddId', helper::FILTER_ID, true);
if($this->getData(['user', $userId])) { if ($this->getData(['user', $userId])) {
self::$inputNotices['userAddId'] = 'Identifiant déjà utilisé'; self::$inputNotices['userAddId'] = 'Identifiant déjà utilisé';
$check=false; $check = false;
} }
// Double vérification pour le mot de passe // Double vérification pour le mot de passe
if($this->getInput('userAddPassword', helper::FILTER_STRING_SHORT, true) !== $this->getInput('userAddConfirmPassword', helper::FILTER_STRING_SHORT, true)) { if ($this->getInput('userAddPassword', helper::FILTER_STRING_SHORT, true) !== $this->getInput('userAddConfirmPassword', helper::FILTER_STRING_SHORT, true)) {
self::$inputNotices['userAddConfirmPassword'] = 'Incorrect'; self::$inputNotices['userAddConfirmPassword'] = 'Incorrect';
$check = false; $check = false;
} }
@ -94,7 +96,7 @@ class user extends common {
// Envoie le mail // Envoie le mail
$sent = true; $sent = true;
if($this->getInput('userAddSendMail', helper::FILTER_BOOLEAN) && $check === true) { if ($this->getInput('userAddSendMail', helper::FILTER_BOOLEAN) && $check === true) {
$sent = $this->sendMail( $sent = $this->sendMail(
$userMail, $userMail,
'Compte créé sur ' . $this->getData(['locale', 'title']), 'Compte créé sur ' . $this->getData(['locale', 'title']),
@ -122,13 +124,14 @@ class user extends common {
/** /**
* Suppression * Suppression
*/ */
public function delete() { public function delete()
{
// Accès refusé // Accès refusé
if( if (
// L'utilisateur n'existe pas // L'utilisateur n'existe pas
$this->getData(['user', $this->getUrl(2)]) === null $this->getData(['user', $this->getUrl(2)]) === null
// Groupe insuffisant // Groupe insuffisant
AND ($this->getUrl('group') < self::GROUP_MODERATOR) and ($this->getUrl('group') < self::GROUP_MODERATOR)
) { ) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
@ -144,7 +147,7 @@ class user extends common {
]); ]);
} }
// Bloque la suppression de son propre compte // Bloque la suppression de son propre compte
elseif($this->getUser('id') === $this->getUrl(2)) { elseif ($this->getUser('id') === $this->getUrl(2)) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . 'user', 'redirect' => helper::baseUrl() . 'user',
@ -166,9 +169,12 @@ class user extends common {
/** /**
* Édition * Édition
*/ */
public function edit() { public function edit()
if ($this->getUrl(3) !== $_SESSION['csrf'] && {
$this->getUrl(4) !== $_SESSION['csrf']) { if (
$this->getUrl(3) !== $_SESSION['csrf'] &&
$this->getUrl(4) !== $_SESSION['csrf']
) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . 'user', 'redirect' => helper::baseUrl() . 'user',
@ -176,18 +182,17 @@ class user extends common {
]); ]);
} }
// Accès refusé // Accès refusé
if( if (
// L'utilisateur n'existe pas // L'utilisateur n'existe pas
$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
) )
// Impossible d'éditer un autre utilisateur // Impossible d'éditer un autre utilisateur
OR ($this->getUrl('group') < self::GROUP_MODERATOR) or ($this->getUrl('group') < self::GROUP_MODERATOR)
) )
) { ) {
// Valeurs en sortie // Valeurs en sortie
@ -198,45 +203,41 @@ class user extends common {
// Accès autorisé // Accès autorisé
else { else {
// Soumission du formulaire // Soumission du formulaire
if($this->isPost()) { if ($this->isPost()) {
// Double vérification pour le mot de passe // Double vérification pour le mot de passe
$newPassword = $this->getData(['user', $this->getUrl(2), 'password']); $newPassword = $this->getData(['user', $this->getUrl(2), 'password']);
if($this->getInput('userEditNewPassword')) { if ($this->getInput('userEditNewPassword')) {
// L'ancien mot de passe est correct // L'ancien mot de passe est correct
if(password_verify($this->getInput('userEditOldPassword'), $this->getData(['user', $this->getUrl(2), 'password']))) { if (password_verify($this->getInput('userEditOldPassword'), $this->getData(['user', $this->getUrl(2), 'password']))) {
// La confirmation correspond au mot de passe // La confirmation correspond au mot de passe
if($this->getInput('userEditNewPassword') === $this->getInput('userEditConfirmPassword')) { if ($this->getInput('userEditNewPassword') === $this->getInput('userEditConfirmPassword')) {
$newPassword = $this->getInput('userEditNewPassword', helper::FILTER_PASSWORD, true); $newPassword = $this->getInput('userEditNewPassword', helper::FILTER_PASSWORD, true);
// Déconnexion de l'utilisateur si il change le mot de passe de son propre compte // Déconnexion de l'utilisateur si il change le mot de passe de son propre compte
if($this->getUser('id') === $this->getUrl(2)) { if ($this->getUser('id') === $this->getUrl(2)) {
helper::deleteCookie('ZWII_USER_ID'); helper::deleteCookie('ZWII_USER_ID');
helper::deleteCookie('ZWII_USER_PASSWORD'); helper::deleteCookie('ZWII_USER_PASSWORD');
} }
} } else {
else {
self::$inputNotices['userEditConfirmPassword'] = 'Incorrect'; self::$inputNotices['userEditConfirmPassword'] = 'Incorrect';
} }
} } else {
else {
self::$inputNotices['userEditOldPassword'] = 'Incorrect'; self::$inputNotices['userEditOldPassword'] = 'Incorrect';
} }
} }
// Modification du groupe // Modification du groupe
if( if (
$this->getUser('group') === self::GROUP_ADMIN $this->getUser('group') === self::GROUP_ADMIN
AND $this->getUrl(2) !== $this->getUser('id') and $this->getUrl(2) !== $this->getUser('id')
) { ) {
$newGroup = $this->getInput('userEditGroup', helper::FILTER_INT, true); $newGroup = $this->getInput('userEditGroup', helper::FILTER_INT, true);
} } else {
else {
$newGroup = $this->getData(['user', $this->getUrl(2), 'group']); $newGroup = $this->getData(['user', $this->getUrl(2), 'group']);
} }
// Modification de nom Prénom // Modification de nom Prénom
if($this->getUser('group') === self::GROUP_ADMIN){ if ($this->getUser('group') === self::GROUP_ADMIN) {
$newfirstname = $this->getInput('userEditFirstname', helper::FILTER_STRING_SHORT, true); $newfirstname = $this->getInput('userEditFirstname', helper::FILTER_STRING_SHORT, true);
$newlastname = $this->getInput('userEditLastname', helper::FILTER_STRING_SHORT, true); $newlastname = $this->getInput('userEditLastname', helper::FILTER_STRING_SHORT, true);
} } else {
else{
$newfirstname = $this->getData(['user', $this->getUrl(2), 'firstname']); $newfirstname = $this->getData(['user', $this->getUrl(2), 'firstname']);
$newlastname = $this->getData(['user', $this->getUrl(2), 'lastname']); $newlastname = $this->getData(['user', $this->getUrl(2), 'lastname']);
} }
@ -253,20 +254,20 @@ class user extends common {
'signature' => $this->getInput('userEditSignature', helper::FILTER_INT, true), 'signature' => $this->getInput('userEditSignature', helper::FILTER_INT, true),
'mail' => $this->getInput('userEditMail', helper::FILTER_MAIL, true), 'mail' => $this->getInput('userEditMail', helper::FILTER_MAIL, true),
'password' => $newPassword, 'password' => $newPassword,
'connectFail' => $this->getData(['user',$this->getUrl(2),'connectFail']), 'connectFail' => $this->getData(['user', $this->getUrl(2), 'connectFail']),
'connectTimeout' => $this->getData(['user',$this->getUrl(2),'connectTimeout']), 'connectTimeout' => $this->getData(['user', $this->getUrl(2), 'connectTimeout']),
'accessUrl' => $this->getData(['user',$this->getUrl(2),'accessUrl']), 'accessUrl' => $this->getData(['user', $this->getUrl(2), 'accessUrl']),
'accessTimer' => $this->getData(['user',$this->getUrl(2),'accessTimer']), 'accessTimer' => $this->getData(['user', $this->getUrl(2), 'accessTimer']),
'accessCsrf' => $this->getData(['user',$this->getUrl(2),'accessCsrf']), 'accessCsrf' => $this->getData(['user', $this->getUrl(2), 'accessCsrf']),
'files' => $this->getInput('userEditFiles', helper::FILTER_BOOLEAN) 'files' => $this->getInput('userEditFiles', helper::FILTER_BOOLEAN)
] ]
]); ]);
// Redirection spécifique si l'utilisateur change son mot de passe // Redirection spécifique si l'utilisateur change son mot de passe
if($this->getUser('id') === $this->getUrl(2) AND $this->getInput('userEditNewPassword')) { if ($this->getUser('id') === $this->getUrl(2) and $this->getInput('userEditNewPassword')) {
$redirect = helper::baseUrl() . 'user/login/' . str_replace('/', '_', $this->getUrl()); $redirect = helper::baseUrl() . 'user/login/' . str_replace('/', '_', $this->getUrl());
} }
// Redirection si retour en arrière possible // Redirection si retour en arrière possible
elseif($this->getUser('group') === 3) { elseif ($this->getUser('group') === 3) {
$redirect = helper::baseUrl() . 'user'; $redirect = helper::baseUrl() . 'user';
} }
// Redirection normale // Redirection normale
@ -291,11 +292,12 @@ class user extends common {
/** /**
* Mot de passe perdu * Mot de passe perdu
*/ */
public function forgot() { public function forgot()
{
// Soumission du formulaire // Soumission du formulaire
if($this->isPost()) { if ($this->isPost()) {
$userId = $this->getInput('userForgotId', helper::FILTER_ID, true); $userId = $this->getInput('userForgotId', helper::FILTER_ID, true);
if($this->getData(['user', $userId])) { if ($this->getData(['user', $userId])) {
// Enregistre la date de la demande dans le compte utilisateur // Enregistre la date de la demande dans le compte utilisateur
$this->setData(['user', $userId, 'forgot', time()]); $this->setData(['user', $userId, 'forgot', time()]);
// Crée un id unique pour la réinitialisation // Crée un id unique pour la réinitialisation
@ -335,22 +337,23 @@ class user extends common {
/** /**
* Liste des utilisateurs * Liste des utilisateurs
*/ */
public function index() { public function index()
{
$userIdsFirstnames = helper::arrayColumn($this->getData(['user']), 'firstname'); $userIdsFirstnames = helper::arrayColumn($this->getData(['user']), 'firstname');
ksort($userIdsFirstnames); ksort($userIdsFirstnames);
foreach($userIdsFirstnames as $userId => $userFirstname) { foreach ($userIdsFirstnames as $userId => $userFirstname) {
if ($this->getData(['user', $userId, 'group'])) { if ($this->getData(['user', $userId, 'group'])) {
self::$users[] = [ self::$users[] = [
$userId, $userId,
$userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']), $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']),
self::$groups[$this->getData(['user', $userId, 'group'])], self::$groups[$this->getData(['user', $userId, 'group'])],
template::button('userEdit' . $userId, [ template::button('userEdit' . $userId, [
'href' => helper::baseUrl() . 'user/edit/' . $userId . '/back/'. $_SESSION['csrf'], 'href' => helper::baseUrl() . 'user/edit/' . $userId . '/back/' . $_SESSION['csrf'],
'value' => template::ico('pencil') 'value' => template::ico('pencil')
]), ]),
template::button('userDelete' . $userId, [ template::button('userDelete' . $userId, [
'class' => 'userDelete buttonRed', 'class' => 'userDelete buttonRed',
'href' => helper::baseUrl() . 'user/delete/' . $userId. '/' . $_SESSION['csrf'], 'href' => helper::baseUrl() . 'user/delete/' . $userId . '/' . $_SESSION['csrf'],
'value' => template::ico('cancel') 'value' => template::ico('cancel')
]) ])
]; ];
@ -366,17 +369,18 @@ class user extends common {
/** /**
* Connexion * Connexion
*/ */
public function login() { public function login()
{
// Soumission du formulaire // Soumission du formulaire
$logStatus = ''; $logStatus = '';
if($this->isPost()) { if ($this->isPost()) {
// Lire Id du compte // Lire Id du compte
$userId = $this->getInput('userLoginId', helper::FILTER_ID, true); $userId = $this->getInput('userLoginId', helper::FILTER_ID, true);
// Check le captcha // Check le captcha
if( if (
$this->getData(['config','connect','captcha']) $this->getData(['config', 'connect', 'captcha'])
AND password_verify($this->getInput('userLoginCaptcha', helper::FILTER_INT), $this->getInput('userLoginCaptchaResult') ) === false ) and password_verify($this->getInput('userLoginCaptcha', helper::FILTER_INT), $this->getInput('userLoginCaptchaResult')) === false
{ ) {
$captcha = false; $captcha = false;
} else { } else {
$captcha = true; $captcha = true;
@ -384,22 +388,24 @@ class user extends common {
/** /**
* Aucun compte existant * Aucun compte existant
*/ */
if ( !$this->getData(['user', $userId])) { if (!$this->getData(['user', $userId])) {
$logStatus = 'Compte inconnu'; $logStatus = 'Compte inconnu';
//Stockage de l'IP //Stockage de l'IP
$this->setData([ $this->setData([
'blacklist', 'blacklist',
$userId, $userId,
[ [
'connectFail' => $this->getData(['blacklist',$userId,'connectFail']) + 1, 'connectFail' => $this->getData(['blacklist', $userId, 'connectFail']) + 1,
'lastFail' => time(), 'lastFail' => time(),
'ip' => helper::getIp() 'ip' => helper::getIp()
] ]
]); ]);
// Verrouillage des IP // Verrouillage des IP
$ipBlackList = helper::arrayColumn($this->getData(['blacklist']), 'ip'); $ipBlackList = helper::arrayColumn($this->getData(['blacklist']), 'ip');
if ( $this->getData(['blacklist',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt']) if (
AND in_array($this->getData(['blacklist',$userId,'ip']),$ipBlackList) ) { $this->getData(['blacklist', $userId, 'connectFail']) >= $this->getData(['config', 'connect', 'attempt'])
and in_array($this->getData(['blacklist', $userId, 'ip']), $ipBlackList)
) {
$logStatus = 'Compte inconnu verrouillé'; $logStatus = 'Compte inconnu verrouillé';
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
@ -418,35 +424,37 @@ 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 ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time() if (
AND $this->getData(['user',$userId,'connectFail']) === $this->getData(['config', 'connect', 'attempt']) ) { $this->getData(['user', $userId, 'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time()
$this->setData(['user',$userId,'connectFail',0 ]); and $this->getData(['user', $userId, 'connectFail']) === $this->getData(['config', 'connect', 'attempt'])
$this->setData(['user',$userId,'connectTimeout',0 ]); ) {
$this->setData(['user', $userId, 'connectFail', 0]);
$this->setData(['user', $userId, 'connectTimeout', 0]);
} }
// Check la présence des variables et contrôle du blocage du compte si valeurs dépassées // Check la présence des variables et contrôle du blocage du compte si valeurs dépassées
// Vérification du mot de passe et du groupe // Vérification du mot de passe et du groupe
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'])
AND password_verify($this->getInput('userLoginPassword', helper::FILTER_STRING_SHORT, true), $this->getData(['user', $userId, 'password'])) and password_verify($this->getInput('userLoginPassword', helper::FILTER_STRING_SHORT, true), $this->getData(['user', $userId, 'password']))
AND $this->getData(['user', $userId, 'group']) >= self::GROUP_MEMBER and $this->getData(['user', $userId, 'group']) >= self::GROUP_MEMBER
AND $captcha === true and $captcha === true
) { ) {
// RAZ // RAZ
$this->setData(['user',$userId,'connectFail',0 ]); $this->setData(['user', $userId, 'connectFail', 0]);
$this->setData(['user',$userId,'connectTimeout',0 ]); $this->setData(['user', $userId, 'connectTimeout', 0]);
// Expiration // Expiration
$expire = $this->getInput('userLoginLongTime') ? strtotime("+1 year") : 0; $expire = $this->getInput('userLoginLongTime') ? strtotime("+1 year") : 0;
$c = $this->getInput('userLoginLongTime', helper::FILTER_BOOLEAN) === true ? 'true' : 'false'; $c = $this->getInput('userLoginLongTime', helper::FILTER_BOOLEAN) === true ? 'true' : 'false';
setcookie('ZWII_USER_ID', $userId, $expire, helper::baseUrl(false, false) , '', helper::isHttps(), true); setcookie('ZWII_USER_ID', $userId, $expire, helper::baseUrl(false, false), '', helper::isHttps(), true);
setcookie('ZWII_USER_PASSWORD', $this->getData(['user', $userId, 'password']), $expire, helper::baseUrl(false, false), '', helper::isHttps(), true); setcookie('ZWII_USER_PASSWORD', $this->getData(['user', $userId, 'password']), $expire, helper::baseUrl(false, false), '', helper::isHttps(), true);
setcookie('ZWII_USER_LONGTIME', $c, $expire, helper::baseUrl(false, false), '', helper::isHttps(), true); setcookie('ZWII_USER_LONGTIME', $c, $expire, helper::baseUrl(false, false), '', helper::isHttps(), true);
// Accès multiples avec le même compte // Accès multiples avec le même compte
$this->setData(['user',$userId,'accessCsrf',$_SESSION['csrf']]); $this->setData(['user', $userId, 'accessCsrf', $_SESSION['csrf']]);
// Valeurs en sortie lorsque le site est en maintenance et que l'utilisateur n'est pas administrateur // Valeurs en sortie lorsque le site est en maintenance et que l'utilisateur n'est pas administrateur
if( if (
$this->getData(['config', 'maintenance']) $this->getData(['config', 'maintenance'])
AND $this->getData(['user', $userId, 'group']) < self::GROUP_ADMIN and $this->getData(['user', $userId, 'group']) < self::GROUP_ADMIN
) { ) {
$this->addOutput([ $this->addOutput([
'notification' => 'Seul un administrateur peut se connecter lors d\'une maintenance', 'notification' => 'Seul un administrateur peut se connecter lors d\'une maintenance',
@ -457,7 +465,7 @@ class user extends common {
$logStatus = 'Connexion réussie'; $logStatus = 'Connexion réussie';
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'notification' => 'Bienvenue ' . $this->getData(['user',$userId,'firstname']) . ' ' . $this->getData(['user',$userId,'lastname']) , 'notification' => 'Bienvenue ' . $this->getData(['user', $userId, 'firstname']) . ' ' . $this->getData(['user', $userId, 'lastname']),
'redirect' => helper::baseUrl() . str_replace('_', '/', str_replace('__', '#', $this->getUrl(2))), 'redirect' => helper::baseUrl() . str_replace('_', '/', str_replace('__', '#', $this->getUrl(2))),
'state' => true 'state' => true
]); ]);
@ -467,15 +475,15 @@ class user extends common {
$notification = 'Captcha, identifiant ou mot de passe incorrects'; $notification = 'Captcha, identifiant ou mot de passe incorrects';
$logStatus = $captcha === true ? 'Erreur de mot de passe' : 'Erreur de captcha'; $logStatus = $captcha === true ? 'Erreur de mot de passe' : 'Erreur de captcha';
// Cas 1 le nombre de connexions est inférieur aux tentatives autorisées : incrément compteur d'échec // Cas 1 le nombre de connexions est inférieur aux tentatives autorisées : incrément compteur d'échec
if ($this->getData(['user',$userId,'connectFail']) < $this->getData(['config', 'connect', 'attempt'])) { if ($this->getData(['user', $userId, 'connectFail']) < $this->getData(['config', 'connect', 'attempt'])) {
$this->setData(['user',$userId,'connectFail',$this->getdata(['user',$userId,'connectFail']) + 1 ]); $this->setData(['user', $userId, 'connectFail', $this->getdata(['user', $userId, 'connectFail']) + 1]);
} }
// Cas 2 la limite du nombre de connexion est atteinte : placer le timer // Cas 2 la limite du nombre de connexion est atteinte : placer le timer
if ( $this->getdata(['user',$userId,'connectFail']) == $this->getData(['config', 'connect', 'attempt']) ) { if ($this->getdata(['user', $userId, 'connectFail']) == $this->getData(['config', 'connect', 'attempt'])) {
$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 = 'Accès bloqué ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.'; $notification = 'Accès bloqué ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.';
} }
@ -486,18 +494,20 @@ class user extends common {
} }
} }
} }
// Journalisation // Journalisation
$dataLog = mb_detect_encoding(\PHP81_BC\strftime('%d/%m/%y',time()), 'UTF-8', true) $dataLog = mb_detect_encoding(\PHP81_BC\strftime('%d/%m/%y', time()), 'UTF-8', true)
? \PHP81_BC\strftime('%d/%m/%y',time()) . ';' . \PHP81_BC\strftime('%R',time()) . ';' ? \PHP81_BC\strftime('%d/%m/%y', time()) . ';' . \PHP81_BC\strftime('%R', time()) . ';'
: utf8_encode(\PHP81_BC\strftime('%d/%m/%y',time())) . ';' . utf8_encode(\PHP81_BC\strftime('%R',time())) . ';' ; : utf8_encode(\PHP81_BC\strftime('%d/%m/%y', time())) . ';' . utf8_encode(\PHP81_BC\strftime('%R', time())) . ';';
$dataLog .= helper::getIp($this->getData(['config','connect','anonymousIp'])) . ';'; $dataLog .= helper::getIp($this->getData(['config', 'connect', 'anonymousIp'])) . ';';
$dataLog .= is_null($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);
} }
// 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'];
@ -516,10 +526,13 @@ class user extends common {
/** /**
* Déconnexion * Déconnexion
*/ */
public function logout() { public function logout()
{
// Ne pas effacer l'identifiant mais seulement le mot de passe // Ne pas effacer l'identifiant mais seulement le mot de passe
if (array_key_exists('ZWII_USER_LONGTIME',$_COOKIE) if (
AND $_COOKIE['ZWII_USER_LONGTIME'] !== 'true' ) { array_key_exists('ZWII_USER_LONGTIME', $_COOKIE)
and $_COOKIE['ZWII_USER_LONGTIME'] !== 'true'
) {
helper::deleteCookie('ZWII_USER_ID'); helper::deleteCookie('ZWII_USER_ID');
helper::deleteCookie('ZWII_USER_LONGTIME'); helper::deleteCookie('ZWII_USER_LONGTIME');
} }
@ -536,15 +549,16 @@ class user extends common {
/** /**
* Réinitialisation du mot de passe * Réinitialisation du mot de passe
*/ */
public function reset() { public function reset()
{
// Accès refusé // Accès refusé
if( if (
// L'utilisateur n'existe pas // L'utilisateur n'existe pas
$this->getData(['user', $this->getUrl(2)]) === null $this->getData(['user', $this->getUrl(2)]) === null
// Lien de réinitialisation trop vieux // Lien de réinitialisation trop vieux
OR $this->getData(['user', $this->getUrl(2), 'forgot']) + 86400 < time() or $this->getData(['user', $this->getUrl(2), 'forgot']) + 86400 < time()
// Id unique incorrecte // Id unique incorrecte
OR $this->getUrl(3) !== md5(json_encode($this->getData(['user', $this->getUrl(2)]))) or $this->getUrl(3) !== md5(json_encode($this->getData(['user', $this->getUrl(2)])))
) { ) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
@ -554,15 +568,14 @@ class user extends common {
// Accès autorisé // Accès autorisé
else { else {
// Soumission du formulaire // Soumission du formulaire
if($this->isPost()) { if ($this->isPost()) {
// Double vérification pour le mot de passe // Double vérification pour le mot de passe
if($this->getInput('userResetNewPassword')) { if ($this->getInput('userResetNewPassword')) {
// La confirmation ne correspond pas au mot de passe // La confirmation ne correspond pas au mot de passe
if($this->getInput('userResetNewPassword', helper::FILTER_STRING_SHORT, true) !== $this->getInput('userResetConfirmPassword', helper::FILTER_STRING_SHORT, true)) { if ($this->getInput('userResetNewPassword', helper::FILTER_STRING_SHORT, true) !== $this->getInput('userResetConfirmPassword', helper::FILTER_STRING_SHORT, true)) {
$newPassword = $this->getData(['user', $this->getUrl(2), 'password']); $newPassword = $this->getData(['user', $this->getUrl(2), 'password']);
self::$inputNotices['userResetConfirmPassword'] = 'Incorrect'; self::$inputNotices['userResetConfirmPassword'] = 'Incorrect';
} } else {
else {
$newPassword = $this->getInput('userResetNewPassword', helper::FILTER_PASSWORD, true); $newPassword = $this->getInput('userResetNewPassword', helper::FILTER_PASSWORD, true);
} }
// Modifie le mot de passe // Modifie le mot de passe
@ -570,8 +583,8 @@ class user extends common {
// Réinitialise la date de la demande // Réinitialise la date de la demande
$this->setData(['user', $this->getUrl(2), 'forgot', 0]); $this->setData(['user', $this->getUrl(2), 'forgot', 0]);
// Réinitialise le blocage // Réinitialise le blocage
$this->setData(['user', $this->getUrl(2),'connectFail',0 ]); $this->setData(['user', $this->getUrl(2), 'connectFail', 0]);
$this->setData(['user', $this->getUrl(2),'connectTimeout',0 ]); $this->setData(['user', $this->getUrl(2), 'connectTimeout', 0]);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'notification' => 'Nouveau mot de passe enregistré', 'notification' => 'Nouveau mot de passe enregistré',
@ -593,66 +606,69 @@ class user extends common {
/** /**
* Importation CSV d'utilisateurs * Importation CSV d'utilisateurs
*/ */
public function import() { public function import()
{
// Soumission du formulaire // Soumission du formulaire
$notification = ''; $notification = '';
$success = true; $success = true;
if($this->isPost()) { if ($this->isPost()) {
// Lecture du CSV et construction du tableau // Lecture du CSV et construction du tableau
$file = $this->getInput('userImportCSVFile',helper::FILTER_STRING_SHORT, true); $file = $this->getInput('userImportCSVFile', helper::FILTER_STRING_SHORT, true);
$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) { return str_getcsv($row, $this->getInput('userImportSeparator') ); }, file($filePath)); $rows = array_map(function ($row) {
return str_getcsv($row, $this->getInput('userImportSeparator'));
}, 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);
} }
// Traitement des données // Traitement des données
foreach($csv as $item ) { foreach ($csv as $item) {
// Données valides // Données valides
if( array_key_exists('id', $item) if (
AND array_key_exists('prenom',$item) array_key_exists('id', $item)
AND array_key_exists('nom',$item) and array_key_exists('prenom', $item)
AND array_key_exists('groupe',$item) and array_key_exists('nom', $item)
AND array_key_exists('email',$item) and array_key_exists('groupe', $item)
AND $item['nom'] and array_key_exists('email', $item)
AND $item['prenom'] and $item['nom']
AND $item['id'] and $item['prenom']
AND $item['email'] and $item['id']
AND $item['groupe'] and $item['email']
and $item['groupe']
) { ) {
// 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)])) {
{
// Notification du doublon // Notification du doublon
$item['notification'] = template::ico('cancel'); $item['notification'] = template::ico('cancel');
// Création du tableau de confirmation // Création du tableau de confirmation
self::$users[] = [ self::$users[] = [
helper::filter($item['id'] , helper::FILTER_ID), helper::filter($item['id'], helper::FILTER_ID),
$item['nom'], $item['nom'],
$item['prenom'], $item['prenom'],
self::$groups[$item['groupe']], self::$groups[$item['groupe']],
$item['prenom'], $item['prenom'],
helper::filter($item['email'] , helper::FILTER_MAIL), helper::filter($item['email'], helper::FILTER_MAIL),
$item['notification'] $item['notification']
]; ];
// L'utilisateur n'existe pas // L'utilisateur n'existe pas
} else { } else {
// Nettoyage de l'identifiant // Nettoyage de l'identifiant
$userId = helper::filter($item['id'] , helper::FILTER_ID); $userId = helper::filter($item['id'], helper::FILTER_ID);
// 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'],
@ -663,12 +679,15 @@ class user extends common {
"accessUrl" => null, "accessUrl" => null,
"accessTimer" => null, "accessTimer" => null,
"accessCsrf" => null "accessCsrf" => null
]]); ]
]);
// 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 ($create if (
AND $this->getInput('userImportNotification',helper::FILTER_BOOLEAN) === true) { $create
and $this->getInput('userImportNotification', helper::FILTER_BOOLEAN) === true
) {
$sent = $this->sendMail( $sent = $this->sendMail(
$item['email'], $item['email'],
'Compte créé sur ' . $this->getData(['locale', 'title']), 'Compte créé sur ' . $this->getData(['locale', 'title']),
@ -679,7 +698,7 @@ class user extends common {
); );
if ($sent === true) { if ($sent === true) {
// Mail envoyé changement de l'icône // Mail envoyé changement de l'icône
$item['notification'] = template::ico('mail') ; $item['notification'] = template::ico('mail');
} }
} }
// Création du tableau de confirmation // Création du tableau de confirmation
@ -696,10 +715,10 @@ class user extends common {
} }
} }
if (empty(self::$users)) { if (empty(self::$users)) {
$notification = 'Rien à importer, erreur de format ou fichier incorrect' ; $notification = 'Rien à importer, erreur de format ou fichier incorrect';
$success = false; $success = false;
} else { } else {
$notification = 'Importation effectuée' ; $notification = 'Importation effectuée';
$success = true; $success = true;
} }
} else { } else {
@ -715,5 +734,4 @@ class user extends common {
'state' => $success 'state' => $success
]); ]);
} }
} }