forked from ZwiiCMS-Team/ZwiiCMS
Amélioration journalisation
This commit is contained in:
parent
03b9ee2094
commit
aa2bfa5ddb
@ -333,6 +333,7 @@ class user extends common {
|
|||||||
*/
|
*/
|
||||||
public function login() {
|
public function login() {
|
||||||
// Soumission du formulaire
|
// Soumission du formulaire
|
||||||
|
$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);
|
||||||
@ -341,29 +342,15 @@ class user extends common {
|
|||||||
$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 )
|
||||||
{
|
{
|
||||||
//self::$inputNotices['userLoginCaptcha'] = 'Incorrect';
|
$captcha = false;
|
||||||
$notification = 'Captcha 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 = 'Accès bloqué ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.';
|
|
||||||
}
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'notification' => $notification
|
|
||||||
]);
|
|
||||||
} else {
|
} else {
|
||||||
|
$captcha = true;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Aucun compte existant
|
* Aucun compte existant
|
||||||
*/
|
*/
|
||||||
if ( !$this->getData(['user', $userId])) {
|
if ( !$this->getData(['user', $userId])) {
|
||||||
|
$logStatus = 'Compte inconnu';
|
||||||
//Stockage de l'IP
|
//Stockage de l'IP
|
||||||
$this->setData([
|
$this->setData([
|
||||||
'blacklist',
|
'blacklist',
|
||||||
@ -378,6 +365,7 @@ class user extends common {
|
|||||||
$ipBlackList = helper::arrayCollumn($this->getData(['blacklist']), 'ip');
|
$ipBlackList = helper::arrayCollumn($this->getData(['blacklist']), 'ip');
|
||||||
if ( $this->getData(['blacklist',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt'])
|
if ( $this->getData(['blacklist',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt'])
|
||||||
AND in_array($this->getData(['blacklist',$userId,'ip']),$ipBlackList) ) {
|
AND in_array($this->getData(['blacklist',$userId,'ip']),$ipBlackList) ) {
|
||||||
|
$logStatus = 'Compte inconnu verrouillé';
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'notification' => 'Compte verrouillé',
|
'notification' => 'Compte verrouillé',
|
||||||
@ -387,7 +375,7 @@ class user extends common {
|
|||||||
} else {
|
} else {
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'notification' => 'Identifiant ou mot de passe incorrects'
|
'notification' => 'Captcha, identifiant ou mot de passe incorrects'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -407,6 +395,7 @@ class user extends common {
|
|||||||
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
|
||||||
) {
|
) {
|
||||||
// RAZ
|
// RAZ
|
||||||
$this->setData(['user',$userId,'connectFail',0 ]);
|
$this->setData(['user',$userId,'connectFail',0 ]);
|
||||||
@ -430,6 +419,7 @@ class user extends common {
|
|||||||
'state' => false
|
'state' => false
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
|
$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']) ,
|
||||||
@ -439,7 +429,8 @@ class user extends common {
|
|||||||
}
|
}
|
||||||
// Sinon notification d'échec
|
// Sinon notification d'échec
|
||||||
} else {
|
} else {
|
||||||
$notification = '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';
|
||||||
// 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 ]);
|
||||||
@ -452,18 +443,7 @@ class user extends common {
|
|||||||
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.';
|
||||||
}
|
}
|
||||||
// Journalisation
|
|
||||||
$dataLog = mb_detect_encoding(strftime('%d/%m/%y',time()), 'UTF-8', true)
|
|
||||||
? strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';'
|
|
||||||
: utf8_encode(strftime('%d/%m/%y',time())) . ';' . utf8_encode(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' => $notification
|
||||||
@ -471,7 +451,19 @@ class user extends common {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Journalisation
|
||||||
|
$dataLog = mb_detect_encoding(strftime('%d/%m/%y',time()), 'UTF-8', true)
|
||||||
|
? strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';'
|
||||||
|
: utf8_encode(strftime('%d/%m/%y',time())) . ';' . utf8_encode(strftime('%R',time())) . ';' ;
|
||||||
|
$dataLog .= helper::getIp() . ';';
|
||||||
|
$dataLog .= $this->getInput('userLoginId', helper::FILTER_ID, true) . ';' ;
|
||||||
|
$dataLog .= $this->getUrl() .';' ;
|
||||||
|
$dataLog .= $logStatus ;
|
||||||
|
$dataLog .= PHP_EOL;
|
||||||
|
if ($this->getData(['config','connect','log'])) {
|
||||||
|
file_put_contents(self::DATA_DIR . 'journal.log', $dataLog, FILE_APPEND);
|
||||||
}
|
}
|
||||||
|
// 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'];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user