diff --git a/core/module/user/user.php b/core/module/user/user.php old mode 100644 new mode 100755 index 0b6678d7..085b384c --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -26,6 +26,15 @@ class user extends common { ]; public static $users = []; + //Paramètre pour choix de la signature + public static $signature = [ + 1 => 'Identifiant', + 2 => 'Pseudo', + 3 => 'Prénom Nom', + 4 => 'Nom Prénom' + ]; + + /** * Ajout */ @@ -48,9 +57,12 @@ class user extends common { $userFirstname = $this->getInput('userAddFirstname', helper::FILTER_STRING_SHORT, true); $userLastname = $this->getInput('userAddLastname', helper::FILTER_STRING_SHORT, true); $userMail = $this->getInput('userAddMail', helper::FILTER_MAIL, true); + $userPseudo = $this->getInput('userAddPseudo', helper::FILTER_STRING_SHORT, true); + $usersignature = $this->getInput('userAddSignature', helper::FILTER_STRING_SHORT, true); // Pas de nom saisi if (empty($userFirstname) || empty($userLastname) || + empty($userPseudo) || empty($this->getInput('userAddPassword', helper::FILTER_STRING_SHORT, true)) || empty($this->getInput('userAddConfirmPassword', helper::FILTER_STRING_SHORT, true))) { $check=false; @@ -65,8 +77,10 @@ class user extends common { 'forgot' => 0, 'group' => $this->getInput('userAddGroup', helper::FILTER_INT, true), 'lastname' => $userLastname, + 'pseudo' => $userPseudo, + 'signature' => $usersignature, 'mail' => $userMail, - 'password' => $this->getInput('userAddPassword', helper::FILTER_PASSWORD, true), + 'password' => $this->getInput('userAddPassword', helper::FILTER_PASSWORD, true) ] ]); } @@ -210,15 +224,26 @@ class user extends common { else { $newGroup = $this->getData(['user', $this->getUrl(2), 'group']); } + // Modification de nom Prénom + if($this->getUser('group') === self::GROUP_ADMIN){ + $newfirstname = $this->getInput('userEditFirstname', helper::FILTER_STRING_SHORT, true); + $newlastname = $this->getInput('userEditLastname', helper::FILTER_STRING_SHORT, true); + } + else{ + $newfirstname = $this->getData(['user', $this->getUrl(2), 'firstname']); + $newlastname = $this->getData(['user', $this->getUrl(2), 'lastname']); + } // Modifie l'utilisateur $this->setData([ 'user', $this->getUrl(2), [ - 'firstname' => $this->getInput('userEditFirstname', helper::FILTER_STRING_SHORT, true), + 'firstname' => $newfirstname, 'forgot' => 0, 'group' => $newGroup, - 'lastname' => $this->getInput('userEditLastname', helper::FILTER_STRING_SHORT, true), + 'lastname' => $newlastname, + 'pseudo' => $this->getInput('userEditPseudo', helper::FILTER_STRING_SHORT, true), + 'signature' => $this->getInput('userEditSignature', helper::FILTER_INT, true), 'mail' => $this->getInput('userEditMail', helper::FILTER_MAIL, true), 'password' => $newPassword, 'connectFail' => $this->getData(['user',$this->getUrl(2),'connectFail']), @@ -338,108 +363,97 @@ class user extends common { if($this->isPost()) { $userId = $this->getInput('userLoginId', helper::FILTER_ID, true); - /** - * Aucun compte existant - */ - if ( !$this->getData(['user', $userId])) { + // le userId n'existe pas, créer ou mettre à jour une entrée dans la liste noire + if( !$this->getData(['user', $userId])) { //Stockage de l'IP $this->setData([ 'blacklist', $userId, [ - 'connectFail' => $this->getData(['blacklist',$userId,'connectFail']) + 1, + 'connectFail' => $this->getData(['blacklist',$userId,'connectFail']) ? $this->getData(['blacklist',$userId,'connectFail']) + 1 : 1, 'lastFail' => time(), - 'ip' => helper::getIp() + 'ip' => $_SERVER['REMOTE_ADDR'] ] ]); - // Verrouillage des IP - $ipBlackList = helper::arrayCollumn($this->getData(['blacklist']), 'ip'); - if ( $this->getData(['blacklist',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt']) - OR in_array($this->getData(['blacklist',$userId,'ip']),$ipBlackList) ) { - // Valeurs en sortie + $notification = 'Identifiant ou mot de passe incorrect'; + } + + /** + * Compte valide : + * Mot de passe + * Groupe + */ + if( $this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time() + 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 $this->getData(['user', $userId, 'group']) >= self::GROUP_MEMBER + ) { + $expire = $this->getInput('userLoginLongTime') ? strtotime("+1 year") : 0; + setcookie('ZWII_USER_ID', $userId, $expire, helper::baseUrl(false, false)); + setcookie('ZWII_USER_PASSWORD', $this->getData(['user', $userId, 'password']), $expire, helper::baseUrl(false, false)); + // Accès multiples avec le même compte + $this->setData(['user',$userId,'accessCsrf',$_SESSION['csrf']]); + // Valeurs en sortie lorsque le site est en maintenance et que l'utilisateur n'est pas administrateur + if( + $this->getData(['config', 'maintenance']) + AND $this->getData(['user', $userId, 'group']) < self::GROUP_ADMIN + ) { $this->addOutput([ - 'notification' => 'Trop de tentatives, compte verrouillé', + 'notification' => 'Seul un administrateur peut se connecter lors d\'une maintenance', 'redirect' => helper::baseUrl(), 'state' => false ]); - } else { - // Valeurs en sortie - $this->addOutput([ - 'notification' => 'Identifiant ou mot de passe incorrect' - ]); } - /** - * Le compte existe - */ - } else { - // 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() - AND $this->getData(['user',$userId,'connectFail']) === $this->getData(['config', 'connect', 'attempt']) ) { + else { + // RAZ compteur échec connexion $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 - // Vérification du mot de passe et du groupe - if ( - ( $this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) ) < time() - 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 $this->getData(['user', $userId, 'group']) >= self::GROUP_MEMBER - ) { - $expire = $this->getInput('userLoginLongTime') ? strtotime("+1 year") : 0; - setcookie('ZWII_USER_ID', $userId, $expire, helper::baseUrl(false, false)); - setcookie('ZWII_USER_PASSWORD', $this->getData(['user', $userId, 'password']), $expire, helper::baseUrl(false, false)); - // Accès multiples avec le même compte - $this->setData(['user',$userId,'accessCsrf',$_SESSION['csrf']]); - // Valeurs en sortie lorsque le site est en maintenance et que l'utilisateur n'est pas administrateur - if( - $this->getData(['config', 'maintenance']) - AND $this->getData(['user', $userId, 'group']) < self::GROUP_ADMIN - ) { - $this->addOutput([ - 'notification' => 'Seul un administrateur peut se connecter lors d\'une maintenance', - 'redirect' => helper::baseUrl(), - 'state' => false - ]); - } else { - // Valeurs en sortie - $this->addOutput([ - 'notification' => 'Connexion réussie', - 'redirect' => helper::baseUrl() . str_replace('_', '/', str_replace('__', '#', $this->getUrl(2))), - 'state' => true - ]); - } - // Sinon notification d'échec - } else { - $notification = 'Identifiant ou mot de passe incorrect'; - // 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'])) { - $this->setData(['user',$userId,'connectFail',$this->getdata(['user',$userId,'connectFail']) + 1 ]); - } - // Cas 2 la limite du nombre de connexion est atteinte : placer le timer - if ( $this->getdata(['user',$userId,'connectFail']) == $this->getData(['config', 'connect', 'attempt']) ) { - $this->setData(['user',$userId,'connectTimeout', time()]); - } - // Cas 3 le délai de bloquage court - if ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) > time() ) { - $notification = 'Trop de tentatives, accès bloqué durant ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.'; - } - // Journalisation - $dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ; - $dataLog .= helper::getIp() . ';'; - $dataLog .= $userId . ';' ; - $dataLog .= $this->getUrl() .';' ; - $dataLog .= 'échec de connexion' ; - $dataLog .= PHP_EOL; - if ($this->getData(['config','connect','log'])) { - file_put_contents(self::DATA_DIR . 'journal.log', $dataLog, FILE_APPEND); - } // Valeurs en sortie $this->addOutput([ - 'notification' => $notification + 'notification' => 'Connexion réussie', + 'redirect' => helper::baseUrl() . str_replace('_', '/', str_replace('__', '#', $this->getUrl(2))), + 'state' => true ]); } } + // Sinon notification d'échec + else { + // L'utilisateur existe : incrémenter le compteur d'échec de connexion + if ( is_array($this->getdata(['user',$userId])) + ) { + $this->setData(['user',$userId,'connectFail',$this->getdata(['user',$userId,'connectFail']) + 1 ]); + // Mettre à jour le timer et notifier + if ( $this->getdata(['user',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt']) + ) { + $notification = 'Trop de tentatives, accès bloqué durant ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.'; + // Incrémenter le timer + if ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time() ) { + $this->setData(['user',$userId,'connectTimeout', time()]); + } + } else { + $notification = 'Identifiant ou mot de passe incorrect'; + } + // L'utilisateur n'existe pas + // Bloquer l'IP après les tentatives autorisées avec ce compte, + } elseif ( + $this->getData(['blacklist',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt']) + ) { + $notification = 'Trop de tentatives, compte verrouillé'; + } + // Journalisation + $dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ; + $dataLog .= $userId . ';' ; + $dataLog .= $this->getUrl() .';' ; + $dataLog .= 'échec de connexion' ; + $dataLog .= PHP_EOL; + if ($this->getData(['config','connect','log'])) { + file_put_contents(self::DATA_DIR . 'journal.log', $dataLog, FILE_APPEND); + } + // Valeurs en sortie + $this->addOutput([ + 'notification' => $notification + ]); + } } // Valeurs en sortie $this->addOutput([ @@ -515,4 +529,4 @@ class user extends common { ]); } } -} \ No newline at end of file +} diff --git a/core/module/user/view/add/add.php b/core/module/user/view/add/add.php old mode 100644 new mode 100755 index 18a52d5d..ad80e4d1 --- a/core/module/user/view/add/add.php +++ b/core/module/user/view/add/add.php @@ -30,6 +30,14 @@ ]); ?> + 'off', + 'label' => 'Pseudo' + ]); ?> + 'Signature', + 'selected' => 1 + ]); ?> 'off', 'label' => 'Adresse mail' @@ -73,9 +81,9 @@ 'label' => 'Confirmation' ]); ?> + 'Prévenir l\'utilisateur par mail'); + ?> - \ No newline at end of file + diff --git a/core/module/user/view/edit/edit.php b/core/module/user/view/edit/edit.php old mode 100644 new mode 100755 index dce157f6..a5ed3d77 --- a/core/module/user/view/edit/edit.php +++ b/core/module/user/view/edit/edit.php @@ -1,7 +1,10 @@ + getUser('group') > 2): $readonly = false; + else: $readonly = true; + endif;?>
- getUser('group') === self::GROUP_ADMIN): ?> + getUrl(3)): ?> 'buttonGrey', 'href' => helper::baseUrl() . 'user', @@ -29,6 +32,7 @@
'off', + 'disabled' => $readonly, 'label' => 'Prénom', 'value' => $this->getData(['user', $this->getUrl(2), 'firstname']) ]); ?> @@ -36,11 +40,21 @@
'off', + 'disabled' => $readonly, 'label' => 'Nom', 'value' => $this->getData(['user', $this->getUrl(2), 'lastname']) ]); ?>
+ 'off', + 'label' => 'Pseudo', + 'value' => $this->getData(['user', $this->getUrl(2), 'pseudo']) + ]); ?> + 'Signature', + 'selected' => $this->getData(['user', $this->getUrl(2), 'signature']) + ]); ?> 'off', 'label' => 'Adresse mail', @@ -98,4 +112,4 @@
- \ No newline at end of file +