Temps de validité à implémenter dans la configuration

This commit is contained in:
Fred Tempez 2024-11-16 08:38:39 +01:00
parent fb439395e7
commit 2ba03c2453
3 changed files with 38 additions and 25 deletions

View File

@ -1176,7 +1176,14 @@ class user extends common
// Vérifier la clé saisie // Vérifier la clé saisie
$targetKey = $this->getData(['user', $this->getUser('id'), 'authKey']); $targetKey = $this->getData(['user', $this->getUser('id'), 'authKey']);
$inputKey = $this->getInput('userAuthKey', helper::FILTER_INT); $inputKey = $this->getInput('userAuthKey', helper::FILTER_INT);
if ($targetKey === $inputKey) { // Supprime la clé stockée et ltemps limite
$this->deleteData(['user', $this->getUser('id'), 'authKey']);
// Réinitialiser le compteur de temps
$this->setData(['user', $this->getUser('id'), 'connectTimeout', 0]);
if (
$targetKey === $inputKey &&
$this->getData(['user', $this->getUser('id'), 'connectTimeout']) + 3600 >= time()
) {
$pageId = $this->getUrl(2); $pageId = $this->getUrl(2);
// La fiche de l'utilisateur contient la clé d'authentification // La fiche de l'utilisateur contient la clé d'authentification
$this->setData(['user', $this->getUser('id'), 'authKey', $this->getInput('ZWII_AUTH_KEY')]); $this->setData(['user', $this->getUser('id'), 'authKey', $this->getInput('ZWII_AUTH_KEY')]);
@ -1212,23 +1219,32 @@ class user extends common
* Envoi d'un email contenant une clé * Envoi d'un email contenant une clé
* Stockage de la clé dans le compte de l'utilisateur * Stockage de la clé dans le compte de l'utilisateur
*/ */
$sent = $this->sendMail( // La clé est envoyée une seule fois
$this->getUser('mail'), $sent = false;
'Tentative de connexion à votre', if (
//'Bonjour <strong>' . $item['prenom'] . ' ' . $item['nom'] . '</strong>,<br><br>' . $this->getData(['user', $this->getUser('id'), 'authKey'])
'<p>Clé de validation à saisir dans le formulaire :</p>' . && $this->getData(['user', $this->getUser('id'), 'connectTimeout']) === 0
'<h1><center>'.$this->getData(['user', $this->getUser('id'), 'authKey']).'</center></h1>', ) {
null, $sent = $this->sendMail(
$this->getData(['config', 'smtp', 'from']) $this->getUser('mail'),
); 'Tentative de connexion à votre',
//'Bonjour <strong>' . $item['prenom'] . ' ' . $item['nom'] . '</strong>,<br><br>' .
'<p>Clé de validation à saisir dans le formulaire :</p>' .
'<h1><center>' . $this->getData(['user', $this->getUser('id'), 'authKey']) . '</center></h1>',
null,
$this->getData(['config', 'smtp', 'from'])
);
// Stocker l'envoi de l'email
$this->setData(['user', $this->getUser('id'), 'connectTimeout', time()]);
}
// Message envoyé sinon la connexion est réalisée pour ne pas bloquer. // Message envoyé sinon la connexion est réalisée pour ne pas bloquer.
if ($sent === true) { if ($sent === false) {
// Valider l'authentification en stockant la clé
// Rediriger vers la page ou l'accueil
} }
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'title' => helper::translate('Authentification'), 'title' => helper::translate('Double authentification'),
'view' => 'auth', 'view' => 'auth',
'display' => self::DISPLAY_LAYOUT_LIGHT, 'display' => self::DISPLAY_LAYOUT_LIGHT,
]); ]);

View File

@ -18,14 +18,6 @@
* admin.css * admin.css
*/ */
#passwordLabel, #passwordIcon {
display: inline-flex;
}
#passwordIcon {
float: right;
}
@media screen and (max-width: 768px) { @media screen and (max-width: 768px) {
#buttonsContainer { #buttonsContainer {
display: grid; display: grid;
@ -36,4 +28,9 @@
#backContainer{ #backContainer{
order: 2; order: 2;
} }
}
#userAuthKey {
text-align: center;
font-size: 1.3rem;
} }

View File

@ -1,8 +1,8 @@
<?php echo template::formOpen('userAuthForm'); ?> <?php echo template::formOpen('userAuthForm'); ?>
<div class="row"> <div class="row">
<div class="col4 offset4"> <div class="col6 offset3">
<?php echo template::text('userAuthKey', [ <?php echo template::text('userAuthKey', [
'label' => helper::translate('Clé') 'label' => helper::translate('Clé reçue par couriel')
]); ?> ]); ?>
</div> </div>
</div> </div>
@ -15,7 +15,7 @@
</div> </div>
<div class="col3 offset7" id="loginContainer"> <div class="col3 offset7" id="loginContainer">
<?php echo template::submit('userLoginSubmit', [ <?php echo template::submit('userLoginSubmit', [
'value' => helper::translate('Connexion'), 'value' => helper::translate('Authentification'),
'ico' => '' 'ico' => ''
]); ?> ]); ?>
</div> </div>