forked from ZwiiCMS-Team/ZwiiCMS
Merge module user
This commit is contained in:
parent
457b536fca
commit
ef3e9db7f5
186
core/module/user/user.php
Normal file → Executable file
186
core/module/user/user.php
Normal file → Executable file
@ -26,6 +26,15 @@ class user extends common {
|
|||||||
];
|
];
|
||||||
public static $users = [];
|
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
|
* Ajout
|
||||||
*/
|
*/
|
||||||
@ -48,9 +57,12 @@ class user extends common {
|
|||||||
$userFirstname = $this->getInput('userAddFirstname', helper::FILTER_STRING_SHORT, true);
|
$userFirstname = $this->getInput('userAddFirstname', helper::FILTER_STRING_SHORT, true);
|
||||||
$userLastname = $this->getInput('userAddLastname', helper::FILTER_STRING_SHORT, true);
|
$userLastname = $this->getInput('userAddLastname', helper::FILTER_STRING_SHORT, true);
|
||||||
$userMail = $this->getInput('userAddMail', helper::FILTER_MAIL, 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
|
// Pas de nom saisi
|
||||||
if (empty($userFirstname) ||
|
if (empty($userFirstname) ||
|
||||||
empty($userLastname) ||
|
empty($userLastname) ||
|
||||||
|
empty($userPseudo) ||
|
||||||
empty($this->getInput('userAddPassword', helper::FILTER_STRING_SHORT, true)) ||
|
empty($this->getInput('userAddPassword', helper::FILTER_STRING_SHORT, true)) ||
|
||||||
empty($this->getInput('userAddConfirmPassword', helper::FILTER_STRING_SHORT, true))) {
|
empty($this->getInput('userAddConfirmPassword', helper::FILTER_STRING_SHORT, true))) {
|
||||||
$check=false;
|
$check=false;
|
||||||
@ -65,8 +77,10 @@ class user extends common {
|
|||||||
'forgot' => 0,
|
'forgot' => 0,
|
||||||
'group' => $this->getInput('userAddGroup', helper::FILTER_INT, true),
|
'group' => $this->getInput('userAddGroup', helper::FILTER_INT, true),
|
||||||
'lastname' => $userLastname,
|
'lastname' => $userLastname,
|
||||||
|
'pseudo' => $userPseudo,
|
||||||
|
'signature' => $usersignature,
|
||||||
'mail' => $userMail,
|
'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 {
|
else {
|
||||||
$newGroup = $this->getData(['user', $this->getUrl(2), 'group']);
|
$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
|
// Modifie l'utilisateur
|
||||||
$this->setData([
|
$this->setData([
|
||||||
'user',
|
'user',
|
||||||
$this->getUrl(2),
|
$this->getUrl(2),
|
||||||
[
|
[
|
||||||
'firstname' => $this->getInput('userEditFirstname', helper::FILTER_STRING_SHORT, true),
|
'firstname' => $newfirstname,
|
||||||
'forgot' => 0,
|
'forgot' => 0,
|
||||||
'group' => $newGroup,
|
'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),
|
'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']),
|
||||||
@ -338,108 +363,97 @@ class user extends common {
|
|||||||
if($this->isPost()) {
|
if($this->isPost()) {
|
||||||
$userId = $this->getInput('userLoginId', helper::FILTER_ID, true);
|
$userId = $this->getInput('userLoginId', helper::FILTER_ID, true);
|
||||||
|
|
||||||
/**
|
// le userId n'existe pas, créer ou mettre à jour une entrée dans la liste noire
|
||||||
* Aucun compte existant
|
if( !$this->getData(['user', $userId])) {
|
||||||
*/
|
|
||||||
if ( !$this->getData(['user', $userId])) {
|
|
||||||
//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']) ? $this->getData(['blacklist',$userId,'connectFail']) + 1 : 1,
|
||||||
'lastFail' => time(),
|
'lastFail' => time(),
|
||||||
'ip' => helper::getIp()
|
'ip' => $_SERVER['REMOTE_ADDR']
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
// Verrouillage des IP
|
$notification = 'Identifiant ou mot de passe incorrect';
|
||||||
$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
|
* 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([
|
$this->addOutput([
|
||||||
'notification' => 'Trop de tentatives, compte verrouillé',
|
'notification' => 'Seul un administrateur peut se connecter lors d\'une maintenance',
|
||||||
'redirect' => helper::baseUrl(),
|
'redirect' => helper::baseUrl(),
|
||||||
'state' => false
|
'state' => false
|
||||||
]);
|
]);
|
||||||
} else {
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'notification' => 'Identifiant ou mot de passe incorrect'
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
/**
|
else {
|
||||||
* Le compte existe
|
// RAZ compteur échec connexion
|
||||||
*/
|
|
||||||
} 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']) ) {
|
|
||||||
$this->setData(['user',$userId,'connectFail',0 ]);
|
$this->setData(['user',$userId,'connectFail',0 ]);
|
||||||
$this->setData(['user',$userId,'connectTimeout',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
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$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
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
@ -515,4 +529,4 @@ class user extends common {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
core/module/user/view/add/add.php
Normal file → Executable file
14
core/module/user/view/add/add.php
Normal file → Executable file
@ -30,6 +30,14 @@
|
|||||||
]); ?>
|
]); ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<?php echo template::text('userAddPseudo', [
|
||||||
|
'autocomplete' => 'off',
|
||||||
|
'label' => 'Pseudo'
|
||||||
|
]); ?>
|
||||||
|
<?php echo template::select('userAddSignature', $module::$signature, [
|
||||||
|
'label' => 'Signature',
|
||||||
|
'selected' => 1
|
||||||
|
]); ?>
|
||||||
<?php echo template::mail('userAddMail', [
|
<?php echo template::mail('userAddMail', [
|
||||||
'autocomplete' => 'off',
|
'autocomplete' => 'off',
|
||||||
'label' => 'Adresse mail'
|
'label' => 'Adresse mail'
|
||||||
@ -73,9 +81,9 @@
|
|||||||
'label' => 'Confirmation'
|
'label' => 'Confirmation'
|
||||||
]); ?>
|
]); ?>
|
||||||
<?php echo template::checkbox('userAddSendMail', true,
|
<?php echo template::checkbox('userAddSendMail', true,
|
||||||
'Prévenir l\'utilisateur par mail');
|
'Prévenir l\'utilisateur par mail');
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php echo template::formClose(); ?>
|
<?php echo template::formClose(); ?>
|
||||||
|
18
core/module/user/view/edit/edit.php
Normal file → Executable file
18
core/module/user/view/edit/edit.php
Normal file → Executable file
@ -1,7 +1,10 @@
|
|||||||
<?php echo template::formOpen('userEditForm'); ?>
|
<?php echo template::formOpen('userEditForm'); ?>
|
||||||
|
<?php if( $this->getUser('group') > 2): $readonly = false;
|
||||||
|
else: $readonly = true;
|
||||||
|
endif;?>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col2">
|
<div class="col2">
|
||||||
<?php if($this->getUser('group') === self::GROUP_ADMIN): ?>
|
<?php if($this->getUrl(3)): ?>
|
||||||
<?php echo template::button('userEditBack', [
|
<?php echo template::button('userEditBack', [
|
||||||
'class' => 'buttonGrey',
|
'class' => 'buttonGrey',
|
||||||
'href' => helper::baseUrl() . 'user',
|
'href' => helper::baseUrl() . 'user',
|
||||||
@ -29,6 +32,7 @@
|
|||||||
<div class="col6">
|
<div class="col6">
|
||||||
<?php echo template::text('userEditFirstname', [
|
<?php echo template::text('userEditFirstname', [
|
||||||
'autocomplete' => 'off',
|
'autocomplete' => 'off',
|
||||||
|
'disabled' => $readonly,
|
||||||
'label' => 'Prénom',
|
'label' => 'Prénom',
|
||||||
'value' => $this->getData(['user', $this->getUrl(2), 'firstname'])
|
'value' => $this->getData(['user', $this->getUrl(2), 'firstname'])
|
||||||
]); ?>
|
]); ?>
|
||||||
@ -36,11 +40,21 @@
|
|||||||
<div class="col6">
|
<div class="col6">
|
||||||
<?php echo template::text('userEditLastname', [
|
<?php echo template::text('userEditLastname', [
|
||||||
'autocomplete' => 'off',
|
'autocomplete' => 'off',
|
||||||
|
'disabled' => $readonly,
|
||||||
'label' => 'Nom',
|
'label' => 'Nom',
|
||||||
'value' => $this->getData(['user', $this->getUrl(2), 'lastname'])
|
'value' => $this->getData(['user', $this->getUrl(2), 'lastname'])
|
||||||
]); ?>
|
]); ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<?php echo template::text('userEditPseudo', [
|
||||||
|
'autocomplete' => 'off',
|
||||||
|
'label' => 'Pseudo',
|
||||||
|
'value' => $this->getData(['user', $this->getUrl(2), 'pseudo'])
|
||||||
|
]); ?>
|
||||||
|
<?php echo template::select('userEditSignature', $module::$signature, [
|
||||||
|
'label' => 'Signature',
|
||||||
|
'selected' => $this->getData(['user', $this->getUrl(2), 'signature'])
|
||||||
|
]); ?>
|
||||||
<?php echo template::mail('userEditMail', [
|
<?php echo template::mail('userEditMail', [
|
||||||
'autocomplete' => 'off',
|
'autocomplete' => 'off',
|
||||||
'label' => 'Adresse mail',
|
'label' => 'Adresse mail',
|
||||||
@ -98,4 +112,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php echo template::formClose(); ?>
|
<?php echo template::formClose(); ?>
|
||||||
|
Loading…
Reference in New Issue
Block a user