ZwiiCMS/core/module/user/user.php

1105 lines
40 KiB
PHP
Raw Normal View History

2018-04-02 08:29:19 +02:00
<?php
/**
* This file is part of Zwii.
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
2021-02-17 13:49:58 +01:00
* @author Frédéric Tempez <frederic.tempez@outlook.com>
2023-01-09 10:23:32 +01:00
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
* @link http://zwiicms.fr/
2018-04-02 08:29:19 +02:00
*/
2022-09-29 08:45:59 +02:00
class user extends common
{
2018-04-02 08:29:19 +02:00
public static $actions = [
'add' => self::GROUP_ADMIN,
'delete' => self::GROUP_ADMIN,
2020-10-04 17:14:15 +02:00
'import' => self::GROUP_ADMIN,
'index' => self::GROUP_ADMIN,
2023-02-10 22:27:08 +01:00
'template' => self::GROUP_ADMIN,
2018-04-02 08:29:19 +02:00
'edit' => self::GROUP_MEMBER,
2020-10-04 17:14:15 +02:00
'logout' => self::GROUP_MEMBER,
2018-04-02 08:29:19 +02:00
'forgot' => self::GROUP_VISITOR,
'login' => self::GROUP_VISITOR,
2023-02-10 22:27:08 +01:00
'reset' => self::GROUP_VISITOR,
2023-03-31 17:02:56 +02:00
'profil' => self::GROUP_ADMIN,
'profilEdit' => self::GROUP_ADMIN,
'profilAdd' => self::GROUP_ADMIN,
2018-04-02 08:29:19 +02:00
];
2018-04-02 08:29:19 +02:00
public static $users = [];
2020-07-10 16:57:21 +02:00
//Paramètres pour choix de la signature
2020-07-02 19:53:52 +02:00
public static $signature = [
2020-07-10 16:57:21 +02:00
self::SIGNATURE_ID => 'Identifiant',
self::SIGNATURE_PSEUDO => 'Pseudo',
self::SIGNATURE_FIRSTLASTNAME => 'Prénom Nom',
self::SIGNATURE_LASTFIRSTNAME => 'Nom Prénom'
2020-07-02 19:53:52 +02:00
];
public static $userId = '';
2023-03-10 15:02:49 +01:00
public static $userGroups = [];
2023-05-02 23:37:51 +02:00
public static $userProfils = [];
public static $userProfilsComments = [];
2023-05-02 23:37:51 +02:00
2020-08-10 09:10:20 +02:00
public static $userLongtime = false;
2020-07-02 19:53:52 +02:00
2020-10-05 16:56:30 +02:00
public static $separators = [
';' => ';',
',' => ',',
':' => ':'
];
public static $languagesInstalled = [];
2023-03-22 17:46:08 +01:00
public static $sharePath = [
'/site/file/source/'
];
2023-03-31 17:02:56 +02:00
public static $groupProfils = [
self::GROUP_MEMBER => 'Membre',
self::GROUP_MODERATOR => 'Editeur'
];
2018-04-02 08:29:19 +02:00
/**
* Ajout
*/
2022-09-29 08:45:59 +02:00
public function add()
{
2018-04-02 08:29:19 +02:00
// Soumission du formulaire
2022-09-29 08:45:59 +02:00
if ($this->isPost()) {
$check = true;
2018-04-02 08:29:19 +02:00
// L'identifiant d'utilisateur est indisponible
$userId = $this->getInput('userAddId', helper::FILTER_ID, true);
2022-09-29 08:45:59 +02:00
if ($this->getData(['user', $userId])) {
2018-04-02 08:29:19 +02:00
self::$inputNotices['userAddId'] = 'Identifiant déjà utilisé';
2022-09-29 08:45:59 +02:00
$check = false;
2018-04-02 08:29:19 +02:00
}
// Double vérification pour le mot de passe
2022-09-29 08:45:59 +02:00
if ($this->getInput('userAddPassword', helper::FILTER_STRING_SHORT, true) !== $this->getInput('userAddConfirmPassword', helper::FILTER_STRING_SHORT, true)) {
2018-04-02 08:29:19 +02:00
self::$inputNotices['userAddConfirmPassword'] = 'Incorrect';
$check = false;
}
2018-04-02 08:29:19 +02:00
// Crée l'utilisateur
$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);
2020-09-24 18:01:34 +02:00
2023-05-02 23:37:51 +02:00
// Profil
$group = $this->getInput('userAddGroup', helper::FILTER_INT, true);
$profil = null;
2023-05-06 19:52:33 +02:00
if ($group > 1 || $group < 2) {
2023-05-02 23:37:51 +02:00
$profil = $this->getInput('userAddProfil' . $group, helper::FILTER_INT);
}
2020-09-24 11:34:26 +02:00
// Stockage des données
$this->setData([
'user',
$userId,
[
'firstname' => $userFirstname,
'forgot' => 0,
2023-05-02 23:37:51 +02:00
'group' => $group,
'profil' => $profil,
2020-09-24 11:34:26 +02:00
'lastname' => $userLastname,
2020-10-31 17:55:54 +01:00
'pseudo' => $this->getInput('userAddPseudo', helper::FILTER_STRING_SHORT, true),
'signature' => $this->getInput('userAddSignature', helper::FILTER_INT, true),
2020-09-24 11:34:26 +02:00
'mail' => $userMail,
'password' => $this->getInput('userAddPassword', helper::FILTER_PASSWORD, true),
2023-05-02 23:37:51 +02:00
'connectFail' => null,
'connectTimeout' => null,
'accessUrl' => null,
'accessTimer' => null,
'accessCsrf' => null,
'language' => $this->getInput('userEditLanguage', helper::FILTER_STRING_SHORT),
2020-09-24 11:34:26 +02:00
]
]);
// Envoie le mail
2018-04-02 08:29:19 +02:00
$sent = true;
2022-09-29 08:45:59 +02:00
if ($this->getInput('userAddSendMail', helper::FILTER_BOOLEAN) && $check === true) {
2018-04-02 08:29:19 +02:00
$sent = $this->sendMail(
$userMail,
'Compte créé sur ' . $this->getData(['locale', 'title']),
2018-04-02 08:29:19 +02:00
'Bonjour <strong>' . $userFirstname . ' ' . $userLastname . '</strong>,<br><br>' .
2023-03-10 10:19:22 +01:00
'Un administrateur vous a créé un compte sur le site ' . $this->getData(['locale', 'title']) . '. Vous trouverez ci-dessous les détails de votre compte.<br><br>' .
'<strong>Identifiant du compte :</strong> ' . $this->getInput('userAddId') . '<br>' .
'<small>Nous ne conservons pas les mots de passe, en conséquence nous vous conseillons de conserver ce message tant que vous ne vous êtes pas connecté. Vous pourrez modifier votre mot de passe après votre première connexion.</small>',
2023-02-23 16:02:06 +01:00
null,
$this->getData(['config', 'smtp', 'from']),
2018-04-02 08:29:19 +02:00
);
}
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'user',
2022-10-11 10:33:44 +02:00
'notification' => $sent === true ? helper::translate('Utilisateur créé') : $sent,
'state' => $sent === true ? true : null
2018-04-02 08:29:19 +02:00
]);
}
2023-05-02 23:37:51 +02:00
// Langues disponibles pour l'interface de l'utilisateur
2023-05-02 23:37:51 +02:00
self::$languagesInstalled = $this->getData(['language']);
if (self::$languagesInstalled) {
foreach (self::$languagesInstalled as $lang => $datas) {
self::$languagesInstalled[$lang] = self::$languages[$lang];
}
}
2023-05-02 23:37:51 +02:00
// Profils disponibles
foreach ($this->getData(['profil']) as $profilId => $profilData) {
2023-05-29 18:43:30 +02:00
if ($profilId < self::GROUP_MEMBER) {
continue;
}
if ($profilId === self::GROUP_ADMIN) {
self::$userProfils[$profilId][self::GROUP_ADMIN] = $profilData['name'];
self::$userProfilsComments[$profilId][self::GROUP_ADMIN] = $profilData['comment'];
2023-05-02 23:37:51 +02:00
continue;
}
foreach ($profilData as $key => $value) {
self::$userProfils[$profilId][$key] = $profilData[$key]['name'];
2023-05-29 09:18:32 +02:00
self::$userProfilsComments[$profilId][$key] = $profilData[$key]['name'] . ' : ' . $profilData[$key]['comment'];
}
}
2023-05-02 23:37:51 +02:00
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Nouvel utilisateur'),
2018-04-02 08:29:19 +02:00
'view' => 'add'
]);
}
/**
* Suppression
*/
2022-09-29 08:45:59 +02:00
public function delete()
{
2018-04-02 08:29:19 +02:00
// Accès refusé
2022-09-29 08:45:59 +02:00
if (
2018-04-02 08:29:19 +02:00
// L'utilisateur n'existe pas
2019-01-15 13:51:30 +01:00
$this->getData(['user', $this->getUrl(2)]) === null
2018-04-02 08:29:19 +02:00
// Groupe insuffisant
2022-09-29 08:45:59 +02:00
and ($this->getUrl('group') < self::GROUP_MODERATOR)
2018-04-02 08:29:19 +02:00
) {
// Valeurs en sortie
$this->addOutput([
'access' => false
]);
}
2019-01-08 17:55:18 +01:00
// Jeton incorrect
2019-01-15 13:51:30 +01:00
elseif ($this->getUrl(3) !== $_SESSION['csrf']) {
2019-01-08 17:55:18 +01:00
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'user',
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Action interdite')
2019-01-08 17:55:18 +01:00
]);
}
2018-04-02 08:29:19 +02:00
// Bloque la suppression de son propre compte
2022-09-29 08:45:59 +02:00
elseif ($this->getUser('id') === $this->getUrl(2)) {
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'user',
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Impossible de supprimer votre propre compte')
2018-04-02 08:29:19 +02:00
]);
}
// Suppression
else {
2019-01-15 13:51:30 +01:00
$this->deleteData(['user', $this->getUrl(2)]);
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'user',
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Utilisateur supprimé'),
2018-04-02 08:29:19 +02:00
'state' => true
]);
}
}
/**
* Édition
*/
2022-09-29 08:45:59 +02:00
public function edit()
{
if (
$this->getUrl(3) !== $_SESSION['csrf']
2022-09-29 08:45:59 +02:00
) {
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'user',
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Action interdite')
]);
}
2018-04-02 08:29:19 +02:00
// Accès refusé
2022-09-29 08:45:59 +02:00
if (
2018-04-02 08:29:19 +02:00
// L'utilisateur n'existe pas
$this->getData(['user', $this->getUrl(2)]) === null
// Droit d'édition
2022-09-29 08:45:59 +02:00
and (
2023-03-10 10:19:22 +01:00
// Impossible de s'auto-éditer
2022-09-29 08:45:59 +02:00
($this->getUser('id') === $this->getUrl(2)
and $this->getUrl('group') <= self::GROUP_VISITOR
2018-04-02 08:29:19 +02:00
)
// Impossible d'éditer un autre utilisateur
2022-09-29 08:45:59 +02:00
or ($this->getUrl('group') < self::GROUP_MODERATOR)
2018-04-02 08:29:19 +02:00
)
) {
// Valeurs en sortie
$this->addOutput([
'access' => false
]);
}
// Accès autorisé
else {
// Soumission du formulaire
2022-09-29 08:45:59 +02:00
if ($this->isPost()) {
2018-04-02 08:29:19 +02:00
// Double vérification pour le mot de passe
$newPassword = $this->getData(['user', $this->getUrl(2), 'password']);
2022-09-29 08:45:59 +02:00
if ($this->getInput('userEditNewPassword')) {
2018-04-02 08:29:19 +02:00
// L'ancien mot de passe est correct
if (password_verify(html_entity_decode($this->getInput('userEditOldPassword')), $this->getData(['user', $this->getUrl(2), 'password']))) {
2018-04-02 08:29:19 +02:00
// La confirmation correspond au mot de passe
2022-09-29 08:45:59 +02:00
if ($this->getInput('userEditNewPassword') === $this->getInput('userEditConfirmPassword')) {
2018-04-02 08:29:19 +02:00
$newPassword = $this->getInput('userEditNewPassword', helper::FILTER_PASSWORD, true);
// Déconnexion de l'utilisateur si il change le mot de passe de son propre compte
2022-09-29 08:45:59 +02:00
if ($this->getUser('id') === $this->getUrl(2)) {
2018-04-02 08:29:19 +02:00
helper::deleteCookie('ZWII_USER_ID');
helper::deleteCookie('ZWII_USER_PASSWORD');
}
2022-09-29 08:45:59 +02:00
} else {
2022-10-11 10:33:44 +02:00
self::$inputNotices['userEditConfirmPassword'] = helper::translate('Incorrect');
2018-04-02 08:29:19 +02:00
}
2022-09-29 08:45:59 +02:00
} else {
2022-10-11 10:33:44 +02:00
self::$inputNotices['userEditOldPassword'] = helper::translate('Incorrect');
2018-04-02 08:29:19 +02:00
}
}
// Modification du groupe
2022-09-29 08:45:59 +02:00
if (
2018-04-02 08:29:19 +02:00
$this->getUser('group') === self::GROUP_ADMIN
2022-09-29 08:45:59 +02:00
and $this->getUrl(2) !== $this->getUser('id')
2018-04-02 08:29:19 +02:00
) {
$newGroup = $this->getInput('userEditGroup', helper::FILTER_INT, true);
2022-09-29 08:45:59 +02:00
} else {
2018-04-02 08:29:19 +02:00
$newGroup = $this->getData(['user', $this->getUrl(2), 'group']);
}
2020-07-02 19:53:52 +02:00
// Modification de nom Prénom
2022-09-29 08:45:59 +02:00
if ($this->getUser('group') === self::GROUP_ADMIN) {
2020-07-02 19:53:52 +02:00
$newfirstname = $this->getInput('userEditFirstname', helper::FILTER_STRING_SHORT, true);
$newlastname = $this->getInput('userEditLastname', helper::FILTER_STRING_SHORT, true);
2022-09-29 08:45:59 +02:00
} else {
2020-07-02 19:53:52 +02:00
$newfirstname = $this->getData(['user', $this->getUrl(2), 'firstname']);
$newlastname = $this->getData(['user', $this->getUrl(2), 'lastname']);
}
2023-05-06 19:52:33 +02:00
// Profil
$profil = null;
if ($newGroup > 1 || $newGroup < 2) {
$profil = $this->getInput('userEditProfil' . $newGroup, helper::FILTER_INT);
}
2018-04-02 08:29:19 +02:00
// Modifie l'utilisateur
$this->setData([
'user',
$this->getUrl(2),
[
2020-07-02 19:53:52 +02:00
'firstname' => $newfirstname,
2018-04-02 08:29:19 +02:00
'forgot' => 0,
'group' => $newGroup,
2023-05-06 19:52:33 +02:00
'profil' => $profil,
2020-07-02 19:53:52 +02:00
'lastname' => $newlastname,
'pseudo' => $this->getInput('userEditPseudo', helper::FILTER_STRING_SHORT, true),
'signature' => $this->getInput('userEditSignature', helper::FILTER_INT, true),
2018-04-02 08:29:19 +02:00
'mail' => $this->getInput('userEditMail', helper::FILTER_MAIL, true),
'password' => $newPassword,
2022-09-29 08:45:59 +02:00
'connectFail' => $this->getData(['user', $this->getUrl(2), 'connectFail']),
'connectTimeout' => $this->getData(['user', $this->getUrl(2), 'connectTimeout']),
'accessUrl' => $this->getData(['user', $this->getUrl(2), 'accessUrl']),
'accessTimer' => $this->getData(['user', $this->getUrl(2), 'accessTimer']),
'accessCsrf' => $this->getData(['user', $this->getUrl(2), 'accessCsrf']),
'files' => $this->getInput('userEditFiles', helper::FILTER_BOOLEAN),
'language' => $this->getInput('userEditLanguage', helper::FILTER_STRING_SHORT),
2018-04-02 08:29:19 +02:00
]
]);
// Redirection spécifique si l'utilisateur change son mot de passe
2022-09-29 08:45:59 +02:00
if ($this->getUser('id') === $this->getUrl(2) and $this->getInput('userEditNewPassword')) {
2018-04-02 08:29:19 +02:00
$redirect = helper::baseUrl() . 'user/login/' . str_replace('/', '_', $this->getUrl());
}
// Redirection si retour en arrière possible
2022-09-29 08:45:59 +02:00
elseif ($this->getUser('group') === 3) {
2018-04-02 08:29:19 +02:00
$redirect = helper::baseUrl() . 'user';
}
// Redirection normale
else {
2020-11-24 08:29:53 +01:00
$redirect = helper::baseUrl();
2018-04-02 08:29:19 +02:00
}
// Valeurs en sortie
$this->addOutput([
'redirect' => $redirect,
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Modifications enregistrées'),
2018-04-02 08:29:19 +02:00
'state' => true
]);
}
// Langues disponibles pour l'interface de l'utilisateur
2023-03-01 15:50:41 +01:00
self::$languagesInstalled = $this->getData(['language']);
2023-03-10 15:02:49 +01:00
if (self::$languagesInstalled) {
foreach (self::$languagesInstalled as $lang => $datas) {
self::$languagesInstalled[$lang] = self::$languages[$lang];
}
}
2023-03-10 10:19:22 +01:00
2023-05-02 23:37:51 +02:00
// Profils disponibles
foreach ($this->getData(['profil']) as $profilId => $profilData) {
2023-05-29 18:43:30 +02:00
if ($profilId < self::GROUP_MEMBER) {
continue;
}
if ($profilId === self::GROUP_ADMIN) {
self::$userProfils[$profilId][self::GROUP_ADMIN] = $profilData['name'];
self::$userProfilsComments[$profilId][self::GROUP_ADMIN] = $profilData['comment'];
2023-05-02 23:37:51 +02:00
continue;
}
foreach ($profilData as $key => $value) {
self::$userProfils[$profilId][$key] = $profilData[$key]['name'];
2023-05-29 18:43:30 +02:00
self::$userProfilsComments[$profilId][$key] = $profilData[$key]['name'] . ' : ' . $profilData[$key]['comment'];
2023-05-02 23:37:51 +02:00
}
}
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this->addOutput([
'title' => $this->getData(['user', $this->getUrl(2), 'firstname']) . ' ' . $this->getData(['user', $this->getUrl(2), 'lastname']),
'view' => 'edit'
]);
}
}
/**
* Mot de passe perdu
*/
2022-09-29 08:45:59 +02:00
public function forgot()
{
2018-04-02 08:29:19 +02:00
// Soumission du formulaire
2022-09-29 08:45:59 +02:00
if ($this->isPost()) {
2018-04-02 08:29:19 +02:00
$userId = $this->getInput('userForgotId', helper::FILTER_ID, true);
2022-09-29 08:45:59 +02:00
if ($this->getData(['user', $userId])) {
2018-04-02 08:29:19 +02:00
// Enregistre la date de la demande dans le compte utilisateur
$this->setData(['user', $userId, 'forgot', time()]);
// Crée un id unique pour la réinitialisation
$uniqId = md5(json_encode($this->getData(['user', $userId])));
// Envoi le mail
$sent = $this->sendMail(
$this->getData(['user', $userId, 'mail']),
'Réinitialisation de votre mot de passe',
'Bonjour <strong>' . $this->getData(['user', $userId, 'firstname']) . ' ' . $this->getData(['user', $userId, 'lastname']) . '</strong>,<br><br>' .
2023-03-10 10:19:22 +01:00
'Vous avez demandé à changer le mot de passe lié à votre compte. Vous trouverez ci-dessous un lien vous permettant de modifier celui-ci.<br><br>' .
'<a href="' . helper::baseUrl() . 'user/reset/' . $userId . '/' . $uniqId . '" target="_blank">' . helper::baseUrl() . 'user/reset/' . $userId . '/' . $uniqId . '</a><br><br>' .
'<small>Si nous n\'avez pas demandé à réinitialiser votre mot de passe, veuillez ignorer ce mail.</small>',
2023-02-23 16:02:06 +01:00
null,
$this->getData(['config', 'smtp', 'from']),
2018-04-02 08:29:19 +02:00
);
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => ($sent === true ? helper::translate('Un mail a été envoyé pour confirmer la réinitialisation') : $sent),
2018-04-02 08:29:19 +02:00
'state' => ($sent === true ? true : null)
]);
}
// L'utilisateur n'existe pas
else {
// Valeurs en sortie
$this->addOutput([
2023-03-10 10:19:22 +01:00
'notification' => helper::translate('Utilisateur inexistant')
2018-04-02 08:29:19 +02:00
]);
}
}
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Mot de passe oublié'),
'view' => 'forgot',
2018-04-02 08:29:19 +02:00
'display' => self::DISPLAY_LAYOUT_LIGHT,
]);
}
/**
* Liste des utilisateurs
*/
2022-09-29 08:45:59 +02:00
public function index()
{
$userIdsFirstnames = helper::arrayColumn($this->getData(['user']), 'firstname');
2018-04-02 08:29:19 +02:00
ksort($userIdsFirstnames);
2022-09-29 08:45:59 +02:00
foreach ($userIdsFirstnames as $userId => $userFirstname) {
if ($this->getData(['user', $userId, 'group'])) {
self::$users[] = [
$userId,
$userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']),
2023-03-29 19:28:03 +02:00
helper::translate(self::$groups[(int) $this->getData(['user', $userId, 'group'])]),
template::button('userEdit' . $userId, [
'href' => helper::baseUrl() . 'user/edit/' . $userId . '/' . $_SESSION['csrf'],
2022-02-18 12:43:48 +01:00
'value' => template::ico('pencil'),
2022-10-02 10:59:42 +02:00
'help' => 'Éditer'
]),
template::button('userDelete' . $userId, [
'class' => 'userDelete buttonRed',
2022-09-29 08:45:59 +02:00
'href' => helper::baseUrl() . 'user/delete/' . $userId . '/' . $_SESSION['csrf'],
'value' => template::ico('trash'),
2022-09-05 09:00:23 +02:00
'help' => 'Supprimer'
])
];
}
2018-04-02 08:29:19 +02:00
}
2023-05-02 23:37:51 +02:00
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Utilisateurs'),
2018-04-02 08:29:19 +02:00
'view' => 'index'
]);
}
2023-03-10 10:19:22 +01:00
/**
* Table des groupes
*/
2023-03-31 17:02:56 +02:00
public function profil()
2023-03-10 10:19:22 +01:00
{
2023-03-31 17:02:56 +02:00
foreach ($this->getData(['profil']) as $groupId => $groupData) {
2023-03-29 19:28:03 +02:00
// Membres sans permissions spécifiques
if (
2023-03-31 14:36:19 +02:00
$groupId == self::GROUP_BANNED ||
$groupId == self::GROUP_VISITOR ||
$groupId == self::GROUP_ADMIN
2023-03-29 19:28:03 +02:00
) {
self::$userGroups[$groupId] = [
$groupId,
$groupData['name'],
2023-03-31 14:36:19 +02:00
nl2br($groupData['comment']),
2023-03-31 17:02:56 +02:00
template::button('profilEdit' . $groupId, [
'href' => helper::baseUrl() . 'user/profilEdit/' . $groupId . '/' . $_SESSION['csrf'],
2023-03-29 19:28:03 +02:00
'value' => template::ico('pencil'),
'help' => 'Éditer',
'disabled' => $groupData['readonly'],
]),
template::button('permissionDelete' . $groupId, [
'class' => 'userDelete buttonRed',
'href' => helper::baseUrl() . 'user/permissionDelete/' . $groupId . '/' . $_SESSION['csrf'],
'value' => template::ico('trash'),
'help' => 'Supprimer',
'disabled' => $groupData['readonly'],
])
2023-05-02 23:37:51 +02:00
];
2023-03-31 14:36:19 +02:00
} elseif (
$groupId == self::GROUP_MEMBER ||
$groupId == self::GROUP_MODERATOR
) {
2023-03-29 19:28:03 +02:00
// Enumérer les sous groupes MEMBER et MODERATOR
foreach ($groupData as $subGroupId => $subGroupData) {
2023-05-02 23:37:51 +02:00
self::$userGroups[$groupId . '.' . $subGroupId] = [
2023-03-29 19:28:03 +02:00
$groupId . '-' . $subGroupId,
2023-05-02 23:37:51 +02:00
self::$groups[$groupId] . '<br />Profil : ' . $subGroupData['name'],
2023-03-31 14:36:19 +02:00
nl2br($subGroupData['comment']),
2023-05-02 23:37:51 +02:00
template::button('profilEdit' . $groupId . $subGroupId, [
'href' => helper::baseUrl() . 'user/profilEdit/' . $groupId . '/' . $subGroupId . '/' . $_SESSION['csrf'],
2023-03-29 19:28:03 +02:00
'value' => template::ico('pencil'),
'help' => 'Éditer',
'disabled' => $subGroupData['readonly'],
]),
2023-05-02 23:37:51 +02:00
template::button('profilDelete' . $groupId . $subGroupId, [
2023-03-29 19:28:03 +02:00
'class' => 'userDelete buttonRed',
2023-03-31 17:02:56 +02:00
'href' => helper::baseUrl() . 'user/profilDelete/' . $groupId . '/' . $subGroupId . '/' . $_SESSION['csrf'],
2023-03-29 19:28:03 +02:00
'value' => template::ico('trash'),
'help' => 'Supprimer',
'disabled' => $subGroupData['readonly'],
])
];
}
}
2023-03-10 10:19:22 +01:00
}
// Valeurs en sortie
$this->addOutput([
2023-03-31 17:02:56 +02:00
'title' => helper::translate('Profils des groupes'),
'view' => 'profil'
2023-03-10 10:19:22 +01:00
]);
}
2023-03-10 15:02:49 +01:00
/**
* Edition d'un groupe
*/
2023-03-31 17:02:56 +02:00
public function profilEdit()
2023-03-10 15:02:49 +01:00
{
2023-03-10 17:23:05 +01:00
if (
2023-03-31 14:36:19 +02:00
$this->getUrl(4) !== $_SESSION['csrf']
2023-03-10 17:23:05 +01:00
) {
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'user',
'notification' => helper::translate('Action interdite')
]);
}
2023-03-16 11:38:46 +01:00
2023-03-10 17:23:05 +01:00
// Soumission du formulaire
if ($this->isPost()) {
2023-03-17 15:55:15 +01:00
$this->setData([
2023-03-31 17:02:56 +02:00
'profil',
$this->getInput('profilEditGroup'),
$this->getInput('profilEditProfil'),
2023-03-17 15:55:15 +01:00
[
2023-03-31 17:02:56 +02:00
'name' => $this->getInput('profilEditName', helper::FILTER_STRING_SHORT, true),
2023-03-31 14:36:19 +02:00
'readonly' => false,
2023-03-31 17:02:56 +02:00
'comment' => $this->getInput('profilEditComment', helper::FILTER_STRING_SHORT, true),
2023-05-10 16:50:02 +02:00
'filemanager' => $this->getInput('profilEditFileManager', helper::FILTER_BOOLEAN),
2023-03-17 15:55:15 +01:00
'file' => [
2023-03-31 17:02:56 +02:00
'download' => $this->getInput('profilEditDownload', helper::FILTER_BOOLEAN),
'edit' => $this->getInput('profilEditEdit', helper::FILTER_BOOLEAN),
'create' => $this->getInput('profilEditCreate', helper::FILTER_BOOLEAN),
'rename' => $this->getInput('profilEditRename', helper::FILTER_BOOLEAN),
'upload' => $this->getInput('profilEditUpload', helper::FILTER_BOOLEAN),
'delete' => $this->getInput('profilEditDelete', helper::FILTER_BOOLEAN),
'preview' => $this->getInput('profilEditPreview', helper::FILTER_BOOLEAN),
'duplicate' => $this->getInput('profilEditDuplicate', helper::FILTER_BOOLEAN),
'extract' => $this->getInput('profilEditExtract', helper::FILTER_BOOLEAN),
'copycut' => $this->getInput('profilEditCopycut', helper::FILTER_BOOLEAN),
'chmod' => $this->getInput('profilEditChmod', helper::FILTER_BOOLEAN),
2023-03-17 15:55:15 +01:00
],
'folder' => [
2023-03-31 17:02:56 +02:00
'create' => $this->getInput('profilEditFolderCreate', helper::FILTER_BOOLEAN),
'delete' => $this->getInput('profilEditFolderDelete', helper::FILTER_BOOLEAN),
'rename' => $this->getInput('profilEditFolderRename', helper::FILTER_BOOLEAN),
'copycut' => $this->getInput('profilEditFolderCopycut', helper::FILTER_BOOLEAN),
'chmod' => $this->getInput('profilEditFolderChmod', helper::FILTER_BOOLEAN),
'path' => $this->getInput('profilEditPath'),
2023-05-14 22:59:24 +02:00
],
'page' => [
'add' => $this->getInput('profilEditPageAdd', helper::FILTER_BOOLEAN),
'edit' => $this->getInput('profilEditPageEdit', helper::FILTER_BOOLEAN),
'delete' => $this->getInput('profilEditPageElete', helper::FILTER_BOOLEAN),
'duplicate' => $this->getInput('profilEditPageDuplicate', helper::FILTER_BOOLEAN),
'module' => $this->getInput('profilEditPageModule', helper::FILTER_BOOLEAN),
'cssEditor' => $this->getInput('profilEditPagecssEditor', helper::FILTER_BOOLEAN),
'jsEditor' => $this->getInput('profilEditPagejsEditor', helper::FILTER_BOOLEAN),
2023-05-31 20:44:47 +02:00
],
'blog' => [
'add' => $this->getInput('profilEditBlogAdd', helper::FILTER_BOOLEAN),
'edit' => $this->getInput('profilEditBlogEdit', helper::FILTER_BOOLEAN),
'delete' => $this->getInput('profilEditBlogDElete', helper::FILTER_BOOLEAN),
'config' => $this->getInput('profilEditBlogConfig', helper::FILTER_BOOLEAN),
'option' => $this->getInput('profilEditBlogOption', helper::FILTER_BOOLEAN),
'comment' => $this->getInput('profilEditBlogComment', helper::FILTER_BOOLEAN),
'commentApprouve' => $this->getInput('profilEditBlogCommentApprouve', helper::FILTER_BOOLEAN),
'commentdelete' => $this->getInput('profilEditBlogCommentDelete', helper::FILTER_BOOLEAN),
'commentDeleteAll' => $this->getInput('profilEditBlogCommentDeleteAll', helper::FILTER_BOOLEAN),
],
2023-03-16 11:38:46 +01:00
]
2023-03-10 17:23:05 +01:00
]);
2023-03-31 17:02:56 +02:00
2023-03-17 15:55:15 +01:00
// Valeurs en sortie
$this->addOutput([
2023-03-31 17:02:56 +02:00
'redirect' => helper::baseUrl() . 'user/profil',
2023-03-17 15:55:15 +01:00
'notification' => helper::translate('Modifications enregistrées'),
'state' => true
]);
2023-03-10 17:23:05 +01:00
}
2023-03-10 15:02:49 +01:00
2023-03-22 17:46:08 +01:00
self::$sharePath = $this->getSubdirectories('./site/file/source');
self::$sharePath = array_flip(self::$sharePath);
2023-05-11 19:07:34 +02:00
self::$sharePath = array_merge(['./site/file/source/' => 'Tous les dossiers'], self::$sharePath);
2023-05-11 18:46:46 +02:00
self::$sharePath = array_merge([null => 'Aucun dossier'], self::$sharePath);
2023-03-22 17:46:08 +01:00
2023-03-28 13:43:42 +02:00
// Valeurs en sortie;
2023-03-10 15:02:49 +01:00
$this->addOutput([
2023-05-29 18:43:30 +02:00
'title' => sprintf(helper::translate('Éditer le profil : %s'), $this->getData(['profil', $this->getUrl(2), $this->getUrl(3), 'name'])),
2023-03-31 17:02:56 +02:00
'view' => 'profilEdit'
2023-03-10 15:02:49 +01:00
]);
}
2023-03-31 17:02:56 +02:00
/**
* Ajouter un profil de permission
*/
2023-05-02 23:37:51 +02:00
public function profilAdd()
{
2023-05-10 16:50:02 +02:00
// Soumission du formulaire
if ($this->isPost()) {
2023-05-10 16:58:56 +02:00
// Nombre de profils de ce groupe
$group = $this->getInput('profilAddGroup');
$profil = (string) (count($this->getData(['profil', $group])) + 1);
2023-05-10 16:50:02 +02:00
// Sauvegarder les données
$this->setData([
'profil',
2023-05-10 16:58:56 +02:00
$group,
$profil,
2023-05-10 16:50:02 +02:00
[
'name' => $this->getInput('profilAddName', helper::FILTER_STRING_SHORT, true),
'readonly' => false,
'comment' => $this->getInput('profilAddComment', helper::FILTER_STRING_SHORT, true),
'filemanager' => $this->getInput('profilAddFileManager', helper::FILTER_BOOLEAN),
'file' => [
'download' => $this->getInput('profilAddDownload', helper::FILTER_BOOLEAN),
'edit' => $this->getInput('profilAddEdit', helper::FILTER_BOOLEAN),
'create' => $this->getInput('profilAddCreate', helper::FILTER_BOOLEAN),
'rename' => $this->getInput('profilAddRename', helper::FILTER_BOOLEAN),
'upload' => $this->getInput('profilAddUpload', helper::FILTER_BOOLEAN),
'delete' => $this->getInput('profilAddDelete', helper::FILTER_BOOLEAN),
'preview' => $this->getInput('profilAddPreview', helper::FILTER_BOOLEAN),
'duplicate' => $this->getInput('profilAddDuplicate', helper::FILTER_BOOLEAN),
'extract' => $this->getInput('profilAddExtract', helper::FILTER_BOOLEAN),
'copycut' => $this->getInput('profilAddCopycut', helper::FILTER_BOOLEAN),
'chmod' => $this->getInput('profilAddChmod', helper::FILTER_BOOLEAN),
],
'folder' => [
'create' => $this->getInput('profilAddFolderCreate', helper::FILTER_BOOLEAN),
'delete' => $this->getInput('profilAddFolderDelete', helper::FILTER_BOOLEAN),
'rename' => $this->getInput('profilAddFolderRename', helper::FILTER_BOOLEAN),
'copycut' => $this->getInput('profilAddFolderCopycut', helper::FILTER_BOOLEAN),
'chmod' => $this->getInput('profilAddFolderChmod', helper::FILTER_BOOLEAN),
'path' => $this->getInput('profilAddPath'),
2023-05-14 22:59:24 +02:00
],
'page' => [
'add' => $this->getInput('profilAddPageAdd', helper::FILTER_BOOLEAN),
'edit' => $this->getInput('profilAddPageEdit', helper::FILTER_BOOLEAN),
2023-05-31 20:44:47 +02:00
'delete' => $this->getInput('profilAddPageDElete', helper::FILTER_BOOLEAN),
2023-05-14 22:59:24 +02:00
'duplicate' => $this->getInput('profilAddPageDuplicate', helper::FILTER_BOOLEAN),
'module' => $this->getInput('profilAddPageModule', helper::FILTER_BOOLEAN),
'cssEditor' => $this->getInput('profilAddPagecssEditor', helper::FILTER_BOOLEAN),
'jsEditor' => $this->getInput('profilAddPagejsEditor', helper::FILTER_BOOLEAN),
2023-05-31 20:44:47 +02:00
],
'blog' => [
'add' => $this->getInput('profilAddBlogAdd', helper::FILTER_BOOLEAN),
'edit' => $this->getInput('profilAddBlogEdit', helper::FILTER_BOOLEAN),
'delete' => $this->getInput('profilAddBlogDElete', helper::FILTER_BOOLEAN),
'config' => $this->getInput('profilAddBlogConfig', helper::FILTER_BOOLEAN),
'option' => $this->getInput('profilAddBlogOption', helper::FILTER_BOOLEAN),
'comment' => $this->getInput('profilAddBlogComment', helper::FILTER_BOOLEAN),
'commentApprouve' => $this->getInput('profilAddBlogCommentApprouve', helper::FILTER_BOOLEAN),
'commentdelete' => $this->getInput('profilAddBlogCommentDelete', helper::FILTER_BOOLEAN),
'commentDeleteAll' => $this->getInput('profilAddBlogCommentDeleteAll', helper::FILTER_BOOLEAN),
],
2023-05-10 16:50:02 +02:00
]
]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'user/profil',
'notification' => helper::translate('Modifications enregistrées'),
'state' => true
]);
}
2023-03-31 17:02:56 +02:00
2023-05-11 18:46:46 +02:00
self::$sharePath = $this->getSubdirectories('./site/file/source');
self::$sharePath = array_flip(self::$sharePath);
2023-05-11 19:07:34 +02:00
self::$sharePath = array_merge(['./site/file/source/' => 'Tous les dossiers'], self::$sharePath);
2023-05-11 18:46:46 +02:00
self::$sharePath = array_merge([null => 'Aucun dossier'], self::$sharePath);
2023-03-31 17:02:56 +02:00
// Valeurs en sortie;
$this->addOutput([
'title' => "Ajouter un profil",
'view' => 'profilAdd'
]);
}
2023-03-10 10:19:22 +01:00
2018-04-02 08:29:19 +02:00
/**
* Connexion
*/
2022-09-29 08:45:59 +02:00
public function login()
{
2018-04-02 08:29:19 +02:00
// Soumission du formulaire
2021-01-03 18:41:25 +01:00
$logStatus = '';
2022-09-29 08:45:59 +02:00
if ($this->isPost()) {
2020-12-30 17:41:27 +01:00
// Lire Id du compte
$userId = $this->getInput('userLoginId', helper::FILTER_ID, true);
// Check le captcha
2022-09-29 08:45:59 +02:00
if (
$this->getData(['config', 'connect', 'captcha'])
and password_verify($this->getInput('userLoginCaptcha', helper::FILTER_INT), $this->getInput('userLoginCaptchaResult')) === false
) {
2021-01-03 18:41:25 +01:00
$captcha = false;
2020-10-09 08:37:34 +02:00
} else {
2021-01-03 18:41:25 +01:00
$captcha = true;
}
/**
* Aucun compte existant
*/
2022-09-29 08:45:59 +02:00
if (!$this->getData(['user', $userId])) {
$logStatus = 'Compte inconnu';
2021-01-03 18:41:25 +01:00
//Stockage de l'IP
$this->setData([
'blacklist',
$userId,
[
2022-09-29 08:45:59 +02:00
'connectFail' => $this->getData(['blacklist', $userId, 'connectFail']) + 1,
2021-01-03 18:41:25 +01:00
'lastFail' => time(),
'ip' => helper::getIp()
]
]);
// Verrouillage des IP
$ipBlackList = helper::arrayColumn($this->getData(['blacklist']), 'ip');
2022-09-29 08:45:59 +02:00
if (
$this->getData(['blacklist', $userId, 'connectFail']) >= $this->getData(['config', 'connect', 'attempt'])
and in_array($this->getData(['blacklist', $userId, 'ip']), $ipBlackList)
) {
2021-01-03 18:41:25 +01:00
$logStatus = 'Compte inconnu verrouillé';
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Compte verrouillé'),
2021-01-03 18:41:25 +01:00
'redirect' => helper::baseUrl(),
'state' => false
]);
2021-01-03 18:41:25 +01:00
} else {
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Captcha, identifiant ou mot de passe incorrects')
2021-01-03 18:41:25 +01:00
]);
}
2022-09-29 08:45:59 +02:00
/**
* Le compte existe
*/
} else {
2021-01-03 18:41:25 +01:00
// Cas 4 : le délai de blocage est dépassé et le compte est au max - Réinitialiser
2022-09-29 08:45:59 +02:00
if (
2023-03-10 10:19:22 +01:00
$this->getData(['user', $userId, 'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time()
2022-09-29 08:45:59 +02:00
and $this->getData(['user', $userId, 'connectFail']) === $this->getData(['config', 'connect', 'attempt'])
) {
$this->setData(['user', $userId, 'connectFail', 0]);
$this->setData(['user', $userId, 'connectTimeout', 0]);
2021-01-03 18:41:25 +01:00
}
// 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 (
2022-09-29 08:45:59 +02:00
($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(html_entity_decode($this->getInput('userLoginPassword', helper::FILTER_STRING_SHORT, true)), $this->getData(['user', $userId, 'password']))
2022-09-29 08:45:59 +02:00
and $this->getData(['user', $userId, 'group']) >= self::GROUP_MEMBER
and $captcha === true
2021-01-03 18:41:25 +01:00
) {
// RAZ
2022-09-29 08:45:59 +02:00
$this->setData(['user', $userId, 'connectFail', 0]);
$this->setData(['user', $userId, 'connectTimeout', 0]);
2021-01-03 18:41:25 +01:00
// Expiration
2022-09-29 08:45:59 +02:00
$expire = $this->getInput('userLoginLongTime', helper::FILTER_BOOLEAN) === true ? strtotime("+1 year") : 0;
setcookie('ZWII_USER_ID', $userId, $expire, helper::baseUrl(false, false), '', helper::isHttps(), true);
2021-01-03 18:41:25 +01:00
setcookie('ZWII_USER_PASSWORD', $this->getData(['user', $userId, 'password']), $expire, helper::baseUrl(false, false), '', helper::isHttps(), true);
// Accès multiples avec le même compte
2022-09-29 08:45:59 +02:00
$this->setData(['user', $userId, 'accessCsrf', $_SESSION['csrf']]);
2021-01-03 18:41:25 +01:00
// Valeurs en sortie lorsque le site est en maintenance et que l'utilisateur n'est pas administrateur
2022-09-29 08:45:59 +02:00
if (
2021-01-03 18:41:25 +01:00
$this->getData(['config', 'maintenance'])
2022-09-29 08:45:59 +02:00
and $this->getData(['user', $userId, 'group']) < self::GROUP_ADMIN
2021-01-03 18:41:25 +01:00
) {
2020-07-17 17:27:34 +02:00
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Seul un administrateur peut se connecter lors d\'une maintenance'),
2020-07-17 17:27:34 +02:00
'redirect' => helper::baseUrl(),
'state' => false
]);
2020-07-02 19:53:52 +02:00
} else {
2021-01-03 18:41:25 +01:00
$logStatus = 'Connexion réussie';
2020-07-17 17:27:34 +02:00
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => sprintf(helper::translate('Bienvenue %s %s'), $this->getData(['user', $userId, 'firstname']), $this->getData(['user', $userId, 'lastname'])),
2021-01-03 18:41:25 +01:00
'redirect' => helper::baseUrl() . str_replace('_', '/', str_replace('__', '#', $this->getUrl(2))),
'state' => true
2020-07-17 17:27:34 +02:00
]);
}
2022-09-29 08:45:59 +02:00
// Sinon notification d'échec
2021-01-03 18:41:25 +01:00
} else {
2022-10-11 10:33:44 +02:00
$notification = helper::translate('Captcha, identifiant ou mot de passe incorrects');
2021-01-03 18:41:25 +01:00
$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
2022-09-29 08:45:59 +02:00
if ($this->getData(['user', $userId, 'connectFail']) < $this->getData(['config', 'connect', 'attempt'])) {
$this->setData(['user', $userId, 'connectFail', $this->getdata(['user', $userId, 'connectFail']) + 1]);
2020-07-17 17:27:34 +02:00
}
2021-01-03 18:41:25 +01:00
// Cas 2 la limite du nombre de connexion est atteinte : placer le timer
2022-09-29 08:45:59 +02:00
if ($this->getdata(['user', $userId, 'connectFail']) == $this->getData(['config', 'connect', 'attempt'])) {
$this->setData(['user', $userId, 'connectTimeout', time()]);
2020-07-17 17:27:34 +02:00
}
2021-01-03 18:41:25 +01:00
// Cas 3 le délai de bloquage court
2023-03-29 19:28:03 +02:00
if ($this->getData(['user', $userId, 'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) > time()) {
$notification = sprintf(helper::translate('Accès bloqué %d minutes'), ($this->getData(['config', 'connect', 'timeout']) / 60));
2021-01-03 18:41:25 +01:00
}
// Valeurs en sortie
$this->addOutput([
'notification' => $notification
]);
2020-07-02 19:53:52 +02:00
}
2018-04-02 08:29:19 +02:00
}
}
2021-01-03 18:41:25 +01:00
// Journalisation
2023-04-23 18:51:37 +02:00
$this->saveLog($logStatus);
2021-01-03 18:41:25 +01:00
// Stockage des cookies
if (!empty($_COOKIE['ZWII_USER_ID'])) {
self::$userId = $_COOKIE['ZWII_USER_ID'];
}
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Connexion'),
'view' => 'login',
2018-04-02 08:29:19 +02:00
'display' => self::DISPLAY_LAYOUT_LIGHT,
]);
}
2023-03-10 10:19:22 +01:00
2018-04-02 08:29:19 +02:00
/**
* Déconnexion
*/
2022-09-29 08:45:59 +02:00
public function logout()
{
2022-05-19 15:20:57 +02:00
helper::deleteCookie('ZWII_USER_ID');
2018-04-02 08:29:19 +02:00
helper::deleteCookie('ZWII_USER_PASSWORD');
2023-04-25 11:07:38 +02:00
// Détruit la session
2019-01-13 17:54:42 +01:00
session_destroy();
2023-04-25 11:07:38 +02:00
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this->addOutput([
'notification' => helper::translate('Déconnexion !'),
2018-04-02 08:29:19 +02:00
'redirect' => helper::baseUrl(false),
'state' => true
]);
}
/**
* Réinitialisation du mot de passe
*/
2022-09-29 08:45:59 +02:00
public function reset()
{
2018-04-02 08:29:19 +02:00
// Accès refusé
2022-09-29 08:45:59 +02:00
if (
2018-04-02 08:29:19 +02:00
// L'utilisateur n'existe pas
$this->getData(['user', $this->getUrl(2)]) === null
// Lien de réinitialisation trop vieux
2022-09-29 08:45:59 +02:00
or $this->getData(['user', $this->getUrl(2), 'forgot']) + 86400 < time()
2018-04-02 08:29:19 +02:00
// Id unique incorrecte
2022-09-29 08:45:59 +02:00
or $this->getUrl(3) !== md5(json_encode($this->getData(['user', $this->getUrl(2)])))
2018-04-02 08:29:19 +02:00
) {
// Valeurs en sortie
$this->addOutput([
'access' => false
]);
}
// Accès autorisé
else {
// Soumission du formulaire
2022-09-29 08:45:59 +02:00
if ($this->isPost()) {
2018-04-02 08:29:19 +02:00
// Double vérification pour le mot de passe
2022-09-29 08:45:59 +02:00
if ($this->getInput('userResetNewPassword')) {
2018-04-02 08:29:19 +02:00
// La confirmation ne correspond pas au mot de passe
2022-09-29 08:45:59 +02:00
if ($this->getInput('userResetNewPassword', helper::FILTER_STRING_SHORT, true) !== $this->getInput('userResetConfirmPassword', helper::FILTER_STRING_SHORT, true)) {
2018-04-02 08:29:19 +02:00
$newPassword = $this->getData(['user', $this->getUrl(2), 'password']);
self::$inputNotices['userResetConfirmPassword'] = 'Incorrect';
2022-09-29 08:45:59 +02:00
} else {
2018-04-02 08:29:19 +02:00
$newPassword = $this->getInput('userResetNewPassword', helper::FILTER_PASSWORD, true);
}
// Modifie le mot de passe
$this->setData(['user', $this->getUrl(2), 'password', $newPassword]);
// Réinitialise la date de la demande
$this->setData(['user', $this->getUrl(2), 'forgot', 0]);
2020-11-22 18:56:14 +01:00
// Réinitialise le blocage
2022-09-29 08:45:59 +02:00
$this->setData(['user', $this->getUrl(2), 'connectFail', 0]);
$this->setData(['user', $this->getUrl(2), 'connectTimeout', 0]);
2018-04-02 08:29:19 +02:00
// Valeurs en sortie
$this->addOutput([
2022-10-11 10:33:44 +02:00
'notification' => helper::translate('Nouveau mot de passe enregistré'),
2020-11-22 18:56:14 +01:00
//'redirect' => helper::baseUrl() . 'user/login/' . str_replace('/', '_', $this->getUrl()),
'redirect' => helper::baseUrl(),
2018-04-02 08:29:19 +02:00
'state' => true
]);
}
}
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => helper::translate('Réinitialisation du mot de passe'),
'view' => 'reset',
2020-10-07 19:01:57 +02:00
'display' => self::DISPLAY_LAYOUT_LIGHT,
2018-04-02 08:29:19 +02:00
]);
}
}
2020-10-04 17:14:15 +02:00
/**
* Importation CSV d'utilisateurs
*/
2022-09-29 08:45:59 +02:00
public function import()
{
// Soumission du formulaire
2020-10-06 15:56:49 +02:00
$notification = '';
$success = true;
2022-09-29 08:45:59 +02:00
if ($this->isPost()) {
// Lecture du CSV et construction du tableau
2022-09-29 08:45:59 +02:00
$file = $this->getInput('userImportCSVFile', helper::FILTER_STRING_SHORT, true);
2020-10-06 08:29:14 +02:00
$filePath = self::FILE_DIR . 'source/' . $file;
2022-09-29 08:45:59 +02:00
if ($file and file_exists($filePath)) {
2020-10-08 21:16:28 +02:00
// Analyse et extraction du CSV
2023-03-10 10:19:22 +01:00
$rows = array_map(function ($row) {
2022-09-29 08:45:59 +02:00
return str_getcsv($row, $this->getInput('userImportSeparator'));
}, file($filePath));
2020-10-05 16:56:30 +02:00
$header = array_shift($rows);
2023-03-10 10:19:22 +01:00
$csv = array();
2022-09-29 08:45:59 +02:00
foreach ($rows as $row) {
2020-10-05 16:56:30 +02:00
$csv[] = array_combine($header, $row);
}
2020-10-08 21:16:28 +02:00
// Traitement des données
2022-09-29 08:45:59 +02:00
foreach ($csv as $item) {
2020-10-08 21:16:28 +02:00
// Données valides
2022-09-29 08:45:59 +02:00
if (
array_key_exists('id', $item)
and array_key_exists('prenom', $item)
and array_key_exists('nom', $item)
and array_key_exists('groupe', $item)
and array_key_exists('email', $item)
and $item['nom']
and $item['prenom']
and $item['id']
and $item['email']
and $item['groupe']
2020-10-19 09:53:28 +02:00
) {
2020-12-04 20:57:02 +01:00
// Validation du groupe
$item['groupe'] = (int) $item['groupe'];
2023-03-10 10:19:22 +01:00
$item['groupe'] = ($item['groupe'] >= self::GROUP_BANNED and $item['groupe'] <= self::GROUP_ADMIN)
2022-09-29 08:45:59 +02:00
? $item['groupe'] : 1;
2020-10-08 21:16:28 +02:00
// L'utilisateur existe
2022-09-29 08:45:59 +02:00
if ($this->getData(['user', helper::filter($item['id'], helper::FILTER_ID)])) {
2020-10-08 21:16:28 +02:00
// Notification du doublon
$item['notification'] = template::ico('cancel');
// Création du tableau de confirmation
self::$users[] = [
2022-09-29 08:45:59 +02:00
helper::filter($item['id'], helper::FILTER_ID),
2020-10-08 21:16:28 +02:00
$item['nom'],
$item['prenom'],
self::$groups[$item['groupe']],
$item['prenom'],
2022-09-29 08:45:59 +02:00
helper::filter($item['email'], helper::FILTER_MAIL),
2020-10-08 21:16:28 +02:00
$item['notification']
];
// L'utilisateur n'existe pas
} else {
// Nettoyage de l'identifiant
2022-09-29 08:45:59 +02:00
$userId = helper::filter($item['id'], helper::FILTER_ID);
2020-10-08 21:16:28 +02:00
// Enregistre le user
$create = $this->setData([
2020-10-08 21:16:28 +02:00
'user',
2023-03-10 10:19:22 +01:00
$userId,
[
2020-10-08 21:16:28 +02:00
'firstname' => $item['prenom'],
'forgot' => 0,
2022-09-29 08:45:59 +02:00
'group' => $item['groupe'],
2020-10-08 21:16:28 +02:00
'lastname' => $item['nom'],
'mail' => $item['email'],
'pseudo' => $item['prenom'],
2023-03-10 10:19:22 +01:00
'signature' => 1,
// Pseudo
'password' => uniqid(),
// A modifier à la première connexion
2021-05-20 21:52:09 +02:00
"connectFail" => null,
"connectTimeout" => null,
"accessUrl" => null,
"accessTimer" => null,
"accessCsrf" => null
2022-09-29 08:45:59 +02:00
]
]);
2020-10-08 21:16:28 +02:00
// Icône de notification
2023-03-10 10:19:22 +01:00
$item['notification'] = $create ? template::ico('check') : template::ico('cancel');
2020-10-08 21:16:28 +02:00
// Envoi du mail
2022-09-29 08:45:59 +02:00
if (
$create
and $this->getInput('userImportNotification', helper::FILTER_BOOLEAN) === true
) {
2020-10-08 21:16:28 +02:00
$sent = $this->sendMail(
$item['email'],
'Compte créé sur ' . $this->getData(['locale', 'title']),
2020-10-08 21:16:28 +02:00
'Bonjour <strong>' . $item['prenom'] . ' ' . $item['nom'] . '</strong>,<br><br>' .
2023-03-10 10:19:22 +01:00
'Un administrateur vous a créé un compte sur le site ' . $this->getData(['locale', 'title']) . '. Vous trouverez ci-dessous les détails de votre compte.<br><br>' .
'<strong>Identifiant du compte :</strong> ' . $userId . '<br>' .
'<small>Un mot de passe provisoire vous été attribué, à la première connexion cliquez sur Mot de passe Oublié.</small>',
null,
$this->getData(['config', 'smtp', 'from']),
2020-10-08 21:16:28 +02:00
);
if ($sent === true) {
// Mail envoyé changement de l'icône
2022-09-29 08:45:59 +02:00
$item['notification'] = template::ico('mail');
2020-10-08 21:16:28 +02:00
}
}
// Création du tableau de confirmation
self::$users[] = [
$userId,
$item['nom'],
$item['prenom'],
self::$groups[$item['groupe']],
$item['prenom'],
$item['email'],
$item['notification']
];
}
2020-10-05 16:56:30 +02:00
}
}
2020-10-08 12:49:09 +02:00
if (empty(self::$users)) {
2023-03-10 10:19:22 +01:00
$notification = helper::translate('Rien à importer, erreur de format ou fichier incorrect');
2020-10-08 12:49:09 +02:00
$success = false;
} else {
2023-03-10 10:19:22 +01:00
$notification = helper::translate('Importation effectuée');
2020-10-08 12:49:09 +02:00
$success = true;
}
2020-10-05 16:56:30 +02:00
} else {
2022-10-11 10:33:44 +02:00
$notification = helper::translate('Erreur de lecture, vérifiez les permissions');
2020-10-05 16:56:30 +02:00
$success = false;
}
}
2020-10-04 17:14:15 +02:00
// Valeurs en sortie
$this->addOutput([
2022-10-02 10:59:42 +02:00
'title' => 'Importation d\'utilisateurs',
2020-10-05 16:56:30 +02:00
'view' => 'import',
'notification' => $notification,
'state' => $success
2020-10-04 17:14:15 +02:00
]);
}
2023-02-10 22:27:08 +01:00
/**
* Télécharge un modèle
2023-03-10 10:19:22 +01:00
*/
public function template()
{
2023-02-10 22:27:08 +01:00
$file = 'template.csv';
$path = 'core/module/user/ressource/';
// Téléchargement du CSV
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="' . $file . '"');
header('Content-Length: ' . filesize($path . $file));
readfile($path . $file);
exit();
}
2023-03-01 16:11:36 +01:00
2023-03-22 17:46:08 +01:00
/**
* Liste les dossier contenus dans RFM
*/
2023-05-11 18:46:46 +02:00
private function getSubdirectories($dir, $basePath = '')
2023-03-29 19:28:03 +02:00
{
2023-03-22 17:46:08 +01:00
$subdirs = array();
// Ouvrez le répertoire spécifié
$dh = opendir($dir);
// Parcourez tous les fichiers et répertoires dans le répertoire
while (($file = readdir($dh)) !== false) {
2023-03-29 19:28:03 +02:00
// Ignorer les entrées de répertoire parent et actuel
if ($file == '.' || $file == '..') {
continue;
}
// Construisez le chemin complet du fichier ou du répertoire
$path = $dir . '/' . $file;
// Vérifiez si c'est un répertoire
if (is_dir($path)) {
// Construisez la clé et la valeur pour le tableau associatif
2023-05-11 19:07:34 +02:00
$key = $basePath === '' ? ucfirst($file) : $basePath . '/' . $file;
2023-03-29 19:28:03 +02:00
$value = $path . '/';
// Ajouter la clé et la valeur au tableau associatif
$subdirs[$key] = $value;
// Appeler la fonction récursivement pour ajouter les sous-répertoires
$subdirs = array_merge($subdirs, $this->getSubdirectories($path, $key));
}
2023-03-22 17:46:08 +01:00
}
// Fermez le gestionnaire de dossier
closedir($dh);
return $subdirs;
2023-03-29 19:28:03 +02:00
}
2023-03-10 10:19:22 +01:00
}