|
@@ -19,20 +19,20 @@ class user
|
|
|
{
|
|
{
|
|
|
// Récupération des données de l'excel au format Json
|
|
// Récupération des données de l'excel au format Json
|
|
|
db::query("SELECT "
|
|
db::query("SELECT "
|
|
|
- . "" . DB_T_USER . ".id AS id, "
|
|
|
|
|
- . "" . DB_T_USER . ".email ,"
|
|
|
|
|
- . "" . DB_T_USER . ".prenom, "
|
|
|
|
|
- . "" . DB_T_USER . ".nom, "
|
|
|
|
|
- . "" . DB_T_USER . ".cree, "
|
|
|
|
|
- . "" . DB_T_USER . ".last_connect, "
|
|
|
|
|
- . "" . DB_T_USER . ".googleAuthenticator, "
|
|
|
|
|
- . "" . DB_T_USER . ".actif, "
|
|
|
|
|
- . "" . DB_T_USER . ".deleted, "
|
|
|
|
|
- . "" . DB_T_USER . ".id_type, "
|
|
|
|
|
- . "" . DB_T_TYPE_USER . ".type "
|
|
|
|
|
- . "FROM " . DB_T_USER . " "
|
|
|
|
|
- . "INNER JOIN " . DB_T_TYPE_USER . " ON " . DB_T_USER . ".id_type = " . DB_T_TYPE_USER . ".id "
|
|
|
|
|
- . "WHERE " . DB_T_USER . ".id = :id");
|
|
|
|
|
|
|
+ . "" . DB_T_USER . ".id AS id, "
|
|
|
|
|
+ . "" . DB_T_USER . ".email ,"
|
|
|
|
|
+ . "" . DB_T_USER . ".prenom, "
|
|
|
|
|
+ . "" . DB_T_USER . ".nom, "
|
|
|
|
|
+ . "" . DB_T_USER . ".cree, "
|
|
|
|
|
+ . "" . DB_T_USER . ".last_connect, "
|
|
|
|
|
+ . "" . DB_T_USER . ".googleAuthenticator, "
|
|
|
|
|
+ . "" . DB_T_USER . ".actif, "
|
|
|
|
|
+ . "" . DB_T_USER . ".deleted, "
|
|
|
|
|
+ . "" . DB_T_USER . ".id_type, "
|
|
|
|
|
+ . "" . DB_T_TYPE_USER . ".type "
|
|
|
|
|
+ . "FROM " . DB_T_USER . " "
|
|
|
|
|
+ . "INNER JOIN " . DB_T_TYPE_USER . " ON " . DB_T_USER . ".id_type = " . DB_T_TYPE_USER . ".id "
|
|
|
|
|
+ . "WHERE " . DB_T_USER . ".id = :id");
|
|
|
db::bind(':id', $_id);
|
|
db::bind(':id', $_id);
|
|
|
$return = db::single();
|
|
$return = db::single();
|
|
|
$return["tags"] = self::getTags($_id);
|
|
$return["tags"] = self::getTags($_id);
|
|
@@ -44,22 +44,23 @@ class user
|
|
|
*
|
|
*
|
|
|
* @return array Liste des utilisateurs avec leurs informations et tags associés.
|
|
* @return array Liste des utilisateurs avec leurs informations et tags associés.
|
|
|
*/
|
|
*/
|
|
|
- public static function getUsers() {
|
|
|
|
|
|
|
+ public static function getUsers()
|
|
|
|
|
+ {
|
|
|
// Récupération des données de l'excel au format Json
|
|
// Récupération des données de l'excel au format Json
|
|
|
db::query("SELECT "
|
|
db::query("SELECT "
|
|
|
- . "" . DB_T_USER . ".id, "
|
|
|
|
|
- . "" . DB_T_USER . ".email, "
|
|
|
|
|
- . "" . DB_T_USER . ".prenom, "
|
|
|
|
|
- . "" . DB_T_USER . ".nom, "
|
|
|
|
|
- . "" . DB_T_USER . ".cree, "
|
|
|
|
|
- . "" . DB_T_USER . ".last_connect, "
|
|
|
|
|
- . "" . DB_T_USER . ".googleAuthenticator, "
|
|
|
|
|
- . "" . DB_T_USER . ".actif, "
|
|
|
|
|
- . "" . DB_T_USER . ".id_type, "
|
|
|
|
|
- . "" . DB_T_TYPE_USER . ".type "
|
|
|
|
|
- . "FROM " . DB_T_USER . " "
|
|
|
|
|
- . "INNER JOIN " . DB_T_TYPE_USER . " ON " . DB_T_USER . ".id_type = " . DB_T_TYPE_USER . ".id "
|
|
|
|
|
- . "WHERE " . DB_T_USER . ".deleted = 0");
|
|
|
|
|
|
|
+ . "" . DB_T_USER . ".id, "
|
|
|
|
|
+ . "" . DB_T_USER . ".email, "
|
|
|
|
|
+ . "" . DB_T_USER . ".prenom, "
|
|
|
|
|
+ . "" . DB_T_USER . ".nom, "
|
|
|
|
|
+ . "" . DB_T_USER . ".cree, "
|
|
|
|
|
+ . "" . DB_T_USER . ".last_connect, "
|
|
|
|
|
+ . "" . DB_T_USER . ".googleAuthenticator, "
|
|
|
|
|
+ . "" . DB_T_USER . ".actif, "
|
|
|
|
|
+ . "" . DB_T_USER . ".id_type, "
|
|
|
|
|
+ . "" . DB_T_TYPE_USER . ".type "
|
|
|
|
|
+ . "FROM " . DB_T_USER . " "
|
|
|
|
|
+ . "INNER JOIN " . DB_T_TYPE_USER . " ON " . DB_T_USER . ".id_type = " . DB_T_TYPE_USER . ".id "
|
|
|
|
|
+ . "WHERE " . DB_T_USER . ".deleted = 0");
|
|
|
$return = db::resultset();
|
|
$return = db::resultset();
|
|
|
|
|
|
|
|
foreach ($return as $key => $users) {
|
|
foreach ($return as $key => $users) {
|
|
@@ -76,11 +77,12 @@ class user
|
|
|
* @param int $_id Identifiant de l'utilisateur.
|
|
* @param int $_id Identifiant de l'utilisateur.
|
|
|
* @return string Nom complet de l'utilisateur.
|
|
* @return string Nom complet de l'utilisateur.
|
|
|
*/
|
|
*/
|
|
|
- public static function getNameById(int $_id) {
|
|
|
|
|
|
|
+ public static function getNameById(int $_id)
|
|
|
|
|
+ {
|
|
|
db::query("SELECT "
|
|
db::query("SELECT "
|
|
|
- . "CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'name' "
|
|
|
|
|
- . "FROM " . DB_T_USER . " "
|
|
|
|
|
- . "WHERE " . DB_T_USER . ".id = :id");
|
|
|
|
|
|
|
+ . "CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'name' "
|
|
|
|
|
+ . "FROM " . DB_T_USER . " "
|
|
|
|
|
+ . "WHERE " . DB_T_USER . ".id = :id");
|
|
|
db::bind(':id', $_id);
|
|
db::bind(':id', $_id);
|
|
|
return db::single()["name"];
|
|
return db::single()["name"];
|
|
|
}
|
|
}
|
|
@@ -91,11 +93,12 @@ class user
|
|
|
* @param int $_id Identifiant de l'utilisateur.
|
|
* @param int $_id Identifiant de l'utilisateur.
|
|
|
* @return string Secret Google Authenticator.
|
|
* @return string Secret Google Authenticator.
|
|
|
*/
|
|
*/
|
|
|
- public static function getMyGoogleAuthenticator(int $_id){
|
|
|
|
|
|
|
+ public static function getMyGoogleAuthenticator(int $_id)
|
|
|
|
|
+ {
|
|
|
db::query("SELECT "
|
|
db::query("SELECT "
|
|
|
- . "" . DB_T_USER . ".googleAuthenticatorSecret "
|
|
|
|
|
- . "FROM " . DB_T_USER . " "
|
|
|
|
|
- . "WHERE " . DB_T_USER . ".id = :id");
|
|
|
|
|
|
|
+ . "" . DB_T_USER . ".googleAuthenticatorSecret "
|
|
|
|
|
+ . "FROM " . DB_T_USER . " "
|
|
|
|
|
+ . "WHERE " . DB_T_USER . ".id = :id");
|
|
|
db::bind(':id', $_id);
|
|
db::bind(':id', $_id);
|
|
|
return db::single()["googleAuthenticatorSecret"];
|
|
return db::single()["googleAuthenticatorSecret"];
|
|
|
}
|
|
}
|
|
@@ -106,16 +109,31 @@ class user
|
|
|
* @param string $_email Email de l'utilisateur.
|
|
* @param string $_email Email de l'utilisateur.
|
|
|
* @return int 1 si activé, 0 sinon.
|
|
* @return int 1 si activé, 0 sinon.
|
|
|
*/
|
|
*/
|
|
|
- public static function checkGoogleAuthenticator(string $_email){
|
|
|
|
|
|
|
+ public static function checkGoogleAuthenticator(string $_email)
|
|
|
|
|
+ {
|
|
|
db::query("SELECT "
|
|
db::query("SELECT "
|
|
|
- . "" . DB_T_USER . ".googleAuthenticator "
|
|
|
|
|
- . "FROM " . DB_T_USER . " "
|
|
|
|
|
- . "WHERE " . DB_T_USER . ".email = :email");
|
|
|
|
|
|
|
+ . "" . DB_T_USER . ".googleAuthenticator "
|
|
|
|
|
+ . "FROM " . DB_T_USER . " "
|
|
|
|
|
+ . "WHERE " . DB_T_USER . ".email = :email");
|
|
|
db::bind(':email', $_email);
|
|
db::bind(':email', $_email);
|
|
|
$return = db::single();
|
|
$return = db::single();
|
|
|
return (isset($return["googleAuthenticator"])) ? $return["googleAuthenticator"] : 0;
|
|
return (isset($return["googleAuthenticator"])) ? $return["googleAuthenticator"] : 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Vérifie le statut du 2FA d'un utilisateur par son ID.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int $_id Identifiant de l'utilisateur.
|
|
|
|
|
+ * @return int 1 si activé, 0 sinon.
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function check2FAStatus(int $_id): int
|
|
|
|
|
+ {
|
|
|
|
|
+ db::query("SELECT googleAuthenticator FROM " . DB_T_USER . " WHERE id = :id");
|
|
|
|
|
+ db::bind(':id', $_id);
|
|
|
|
|
+ $result = db::single();
|
|
|
|
|
+ return isset($result["googleAuthenticator"]) ? (int)$result["googleAuthenticator"] : 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Insère un jeton JWT pour un utilisateur.
|
|
* Insère un jeton JWT pour un utilisateur.
|
|
|
*
|
|
*
|
|
@@ -123,7 +141,8 @@ class user
|
|
|
* @param string $_jwt Jeton JWT à insérer.
|
|
* @param string $_jwt Jeton JWT à insérer.
|
|
|
* @return bool TRUE si l'insertion est réussie, FALSE sinon.
|
|
* @return bool TRUE si l'insertion est réussie, FALSE sinon.
|
|
|
*/
|
|
*/
|
|
|
- private static function insertJWT($_id_user, $_jwt){
|
|
|
|
|
|
|
+ private static function insertJWT($_id_user, $_jwt)
|
|
|
|
|
+ {
|
|
|
self::deleteJWTbyUSer($_id_user);
|
|
self::deleteJWTbyUSer($_id_user);
|
|
|
|
|
|
|
|
db::query("INSERT INTO " . DB_T_JWT . " (id_user, md5, jwt) VALUES (:id_user, :md5, :jwt)");
|
|
db::query("INSERT INTO " . DB_T_JWT . " (id_user, md5, jwt) VALUES (:id_user, :md5, :jwt)");
|
|
@@ -144,7 +163,8 @@ class user
|
|
|
* @param int $_id_user Identifiant de l'utilisateur.
|
|
* @param int $_id_user Identifiant de l'utilisateur.
|
|
|
* @return bool TRUE si la suppression est réussie, FALSE sinon.
|
|
* @return bool TRUE si la suppression est réussie, FALSE sinon.
|
|
|
*/
|
|
*/
|
|
|
- public static function deleteJWTbyUSer($_id_user){
|
|
|
|
|
|
|
+ public static function deleteJWTbyUSer($_id_user)
|
|
|
|
|
+ {
|
|
|
db::query("DELETE FROM " . DB_T_JWT . " WHERE id_user = :id_user");
|
|
db::query("DELETE FROM " . DB_T_JWT . " WHERE id_user = :id_user");
|
|
|
db::bind(':id_user', $_id_user);
|
|
db::bind(':id_user', $_id_user);
|
|
|
try {
|
|
try {
|
|
@@ -162,7 +182,8 @@ class user
|
|
|
* @param string $_jwt Nouveau jeton JWT.
|
|
* @param string $_jwt Nouveau jeton JWT.
|
|
|
* @return bool TRUE si la mise à jour est réussie, FALSE sinon.
|
|
* @return bool TRUE si la mise à jour est réussie, FALSE sinon.
|
|
|
*/
|
|
*/
|
|
|
- public static function updateJWTbyMd5($_md5, $_jwt){
|
|
|
|
|
|
|
+ public static function updateJWTbyMd5($_md5, $_jwt)
|
|
|
|
|
+ {
|
|
|
db::query("UPDATE " . DB_T_JWT . " SET jwt = :jwt, md5 = :newmd5 WHERE md5 = :md5");
|
|
db::query("UPDATE " . DB_T_JWT . " SET jwt = :jwt, md5 = :newmd5 WHERE md5 = :md5");
|
|
|
db::bind(':md5', $_md5);
|
|
db::bind(':md5', $_md5);
|
|
|
db::bind(':jwt', $_jwt);
|
|
db::bind(':jwt', $_jwt);
|
|
@@ -181,12 +202,13 @@ class user
|
|
|
* @param string $_jwt Jeton JWT.
|
|
* @param string $_jwt Jeton JWT.
|
|
|
* @return array|bool Informations de l'utilisateur ou FALSE si non trouvé.
|
|
* @return array|bool Informations de l'utilisateur ou FALSE si non trouvé.
|
|
|
*/
|
|
*/
|
|
|
- public static function getInfosByJWT($_jwt){
|
|
|
|
|
|
|
+ public static function getInfosByJWT($_jwt)
|
|
|
|
|
+ {
|
|
|
db::query("SELECT id_user, creer FROM " . DB_T_JWT . " WHERE md5 = :md5");
|
|
db::query("SELECT id_user, creer FROM " . DB_T_JWT . " WHERE md5 = :md5");
|
|
|
db::bind(':md5', md5($_jwt));
|
|
db::bind(':md5', md5($_jwt));
|
|
|
$row = db::single();
|
|
$row = db::single();
|
|
|
|
|
|
|
|
- if(isset($row["id_user"])){
|
|
|
|
|
|
|
+ if (isset($row["id_user"])) {
|
|
|
return $row;
|
|
return $row;
|
|
|
} else {
|
|
} else {
|
|
|
return FALSE;
|
|
return FALSE;
|
|
@@ -246,7 +268,8 @@ class user
|
|
|
* @param array $_input Données d'entrée pour la connexion.
|
|
* @param array $_input Données d'entrée pour la connexion.
|
|
|
* @return bool TRUE si la connexion est réussie, FALSE sinon.
|
|
* @return bool TRUE si la connexion est réussie, FALSE sinon.
|
|
|
*/
|
|
*/
|
|
|
- public static function connect(array $_input) {
|
|
|
|
|
|
|
+ public static function connect(array $_input)
|
|
|
|
|
+ {
|
|
|
|
|
|
|
|
$connect = jwt::authenticate($_input);
|
|
$connect = jwt::authenticate($_input);
|
|
|
|
|
|
|
@@ -294,7 +317,8 @@ class user
|
|
|
*
|
|
*
|
|
|
* @param int $_id Identifiant de l'utilisateur.
|
|
* @param int $_id Identifiant de l'utilisateur.
|
|
|
*/
|
|
*/
|
|
|
- private static function updateLastConnect(int $_id){
|
|
|
|
|
|
|
+ private static function updateLastConnect(int $_id)
|
|
|
|
|
+ {
|
|
|
db::query("UPDATE " . DB_T_USER . " SET `last_connect` = CURRENT_TIMESTAMP() WHERE id = :id");
|
|
db::query("UPDATE " . DB_T_USER . " SET `last_connect` = CURRENT_TIMESTAMP() WHERE id = :id");
|
|
|
db::bind(':id', $_id);
|
|
db::bind(':id', $_id);
|
|
|
db::execute();
|
|
db::execute();
|
|
@@ -305,10 +329,11 @@ class user
|
|
|
*
|
|
*
|
|
|
* @param array $_input Données de l'utilisateur à ajouter.
|
|
* @param array $_input Données de l'utilisateur à ajouter.
|
|
|
*/
|
|
*/
|
|
|
- public static function add_user(array $_input){
|
|
|
|
|
|
|
+ public static function add_user(array $_input)
|
|
|
|
|
+ {
|
|
|
db::query("INSERT INTO " . DB_T_USER . " "
|
|
db::query("INSERT INTO " . DB_T_USER . " "
|
|
|
- . "(email, password, googleAuthenticator, googleAuthenticatorSecret, prenom, nom, id_type, actif) "
|
|
|
|
|
- . "VALUES (:email, :password, :googleAuthenticator, :googleAuthenticatorSecret, :prenom, :nom, :id_type, :actif)");
|
|
|
|
|
|
|
+ . "(email, password, googleAuthenticator, googleAuthenticatorSecret, prenom, nom, id_type, actif) "
|
|
|
|
|
+ . "VALUES (:email, :password, :googleAuthenticator, :googleAuthenticatorSecret, :prenom, :nom, :id_type, :actif)");
|
|
|
db::bind(':email', $_input["email"]);
|
|
db::bind(':email', $_input["email"]);
|
|
|
db::bind(':password', md5($_input["password"]));
|
|
db::bind(':password', md5($_input["password"]));
|
|
|
db::bind(':prenom', $_input["prenom"]);
|
|
db::bind(':prenom', $_input["prenom"]);
|
|
@@ -321,7 +346,7 @@ class user
|
|
|
try {
|
|
try {
|
|
|
db::execute();
|
|
db::execute();
|
|
|
|
|
|
|
|
- $tags = tags::textToId($_input["tags"], 1);
|
|
|
|
|
|
|
+ $tags = tags::textToId($_input["tags"], 1);
|
|
|
self::addTags(db::lastInsertId(), $tags);
|
|
self::addTags(db::lastInsertId(), $tags);
|
|
|
alert::recSuccess("La création a bien été prise en compte");
|
|
alert::recSuccess("La création a bien été prise en compte");
|
|
|
} catch (Exception $ex) {
|
|
} catch (Exception $ex) {
|
|
@@ -336,8 +361,9 @@ class user
|
|
|
*
|
|
*
|
|
|
* @return int Identifiant du dernier utilisateur.
|
|
* @return int Identifiant du dernier utilisateur.
|
|
|
*/
|
|
*/
|
|
|
- public static function lastUser(){
|
|
|
|
|
- db::query("SELECT MAX(id) AS id FROM ". DB_T_USER);
|
|
|
|
|
|
|
+ public static function lastUser()
|
|
|
|
|
+ {
|
|
|
|
|
+ db::query("SELECT MAX(id) AS id FROM " . DB_T_USER);
|
|
|
return db::single()["id"];
|
|
return db::single()["id"];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -346,9 +372,10 @@ class user
|
|
|
*
|
|
*
|
|
|
* @param array $_input Données mises à jour de l'utilisateur.
|
|
* @param array $_input Données mises à jour de l'utilisateur.
|
|
|
*/
|
|
*/
|
|
|
- public static function maj_user(array $_input){
|
|
|
|
|
|
|
+ public static function maj_user(array $_input)
|
|
|
|
|
+ {
|
|
|
|
|
|
|
|
- if($_input["password"] != ""){
|
|
|
|
|
|
|
+ if ($_input["password"] != "") {
|
|
|
db::query("UPDATE " . DB_T_USER . " SET password = :password WHERE id = :id");
|
|
db::query("UPDATE " . DB_T_USER . " SET password = :password WHERE id = :id");
|
|
|
db::bind(':password', md5($_input["password"]));
|
|
db::bind(':password', md5($_input["password"]));
|
|
|
db::bind(':id', $_input["id"]);
|
|
db::bind(':id', $_input["id"]);
|
|
@@ -356,12 +383,12 @@ class user
|
|
|
db::execute();
|
|
db::execute();
|
|
|
} catch (Exception $ex) {
|
|
} catch (Exception $ex) {
|
|
|
alert::recError("Erreur lors de la modification du mot de passe");
|
|
alert::recError("Erreur lors de la modification du mot de passe");
|
|
|
- header("Location: /user-" . $_input["id"] .".html");
|
|
|
|
|
|
|
+ header("Location: /user-" . $_input["id"] . ".html");
|
|
|
exit();
|
|
exit();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(self::getMyGoogleAuthenticator($_input["id"]) == NULL){
|
|
|
|
|
|
|
+ if (self::getMyGoogleAuthenticator($_input["id"]) == NULL) {
|
|
|
db::query("UPDATE " . DB_T_USER . " SET googleAuthenticatorSecret = :googleAuthenticatorSecret WHERE id = :id");
|
|
db::query("UPDATE " . DB_T_USER . " SET googleAuthenticatorSecret = :googleAuthenticatorSecret WHERE id = :id");
|
|
|
db::bind(':googleAuthenticatorSecret', googleAuthenticator::createSecret());
|
|
db::bind(':googleAuthenticatorSecret', googleAuthenticator::createSecret());
|
|
|
db::bind(':id', $_input["id"]);
|
|
db::bind(':id', $_input["id"]);
|
|
@@ -369,14 +396,30 @@ class user
|
|
|
db::execute();
|
|
db::execute();
|
|
|
} catch (Exception $ex) {
|
|
} catch (Exception $ex) {
|
|
|
alert::recError("Erreur lors de la création du token de Google Authenticator");
|
|
alert::recError("Erreur lors de la création du token de Google Authenticator");
|
|
|
- header("Location: /user-" . $_input["id"] .".html");
|
|
|
|
|
|
|
+ header("Location: /user-" . $_input["id"] . ".html");
|
|
|
exit();
|
|
exit();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $tags = tags::textToId($_input["tags"], 1);
|
|
|
|
|
|
|
+ $tags = tags::textToId($_input["tags"], 1);
|
|
|
self::addTags($_input["id"], $tags);
|
|
self::addTags($_input["id"], $tags);
|
|
|
|
|
|
|
|
|
|
+ // Vérifier si on active le 2FA (passage de 0 à 1)
|
|
|
|
|
+ $current2FA = self::check2FAStatus($_input["id"]);
|
|
|
|
|
+ $new2FA = isset($_input["googleAuthenticator"]) ? (int)$_input["googleAuthenticator"] : 0;
|
|
|
|
|
+
|
|
|
|
|
+ // Si on veut activer le 2FA et qu'il n'est pas déjà actif, on le met en pending
|
|
|
|
|
+ if ($new2FA == 1 && $current2FA == 0) {
|
|
|
|
|
+ self::set2FAPending($_input["id"]);
|
|
|
|
|
+ $googleAuthValue = 0; // Reste à 0 jusqu'à validation
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $googleAuthValue = $new2FA;
|
|
|
|
|
+ // Si on désactive le 2FA, on supprime aussi le pending
|
|
|
|
|
+ if ($new2FA == 0) {
|
|
|
|
|
+ self::cancel2FAPending($_input["id"]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
db::query("UPDATE " . DB_T_USER . " SET
|
|
db::query("UPDATE " . DB_T_USER . " SET
|
|
|
email = :email,
|
|
email = :email,
|
|
|
prenom = :prenom,
|
|
prenom = :prenom,
|
|
@@ -388,11 +431,11 @@ class user
|
|
|
db::bind(':email', $_input["email"]);
|
|
db::bind(':email', $_input["email"]);
|
|
|
db::bind(':prenom', $_input["prenom"]);
|
|
db::bind(':prenom', $_input["prenom"]);
|
|
|
db::bind(':nom', $_input["nom"]);
|
|
db::bind(':nom', $_input["nom"]);
|
|
|
- db::bind(':googleAuthenticator', $_input["googleAuthenticator"]);
|
|
|
|
|
|
|
+ db::bind(':googleAuthenticator', $googleAuthValue);
|
|
|
db::bind(':id_type', $_input["id_type"]);
|
|
db::bind(':id_type', $_input["id_type"]);
|
|
|
db::bind(':actif', $_input["actif"]);
|
|
db::bind(':actif', $_input["actif"]);
|
|
|
db::bind(':id', $_input["id"]);
|
|
db::bind(':id', $_input["id"]);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
db::execute();
|
|
db::execute();
|
|
|
alert::recSuccess("La modification a bien été prise en compte");
|
|
alert::recSuccess("La modification a bien été prise en compte");
|
|
@@ -409,7 +452,8 @@ class user
|
|
|
* @param float $_idUser Identifiant de l'utilisateur.
|
|
* @param float $_idUser Identifiant de l'utilisateur.
|
|
|
* @return string|null Liste des tags sous forme de chaîne ou NULL si aucun tag.
|
|
* @return string|null Liste des tags sous forme de chaîne ou NULL si aucun tag.
|
|
|
*/
|
|
*/
|
|
|
- static public function getTags(float $_idUser){
|
|
|
|
|
|
|
+ static public function getTags(float $_idUser)
|
|
|
|
|
+ {
|
|
|
db::query("SELECT "
|
|
db::query("SELECT "
|
|
|
. "" . DB_T_TAGS . ".label "
|
|
. "" . DB_T_TAGS . ".label "
|
|
|
. "FROM " . DB_T_USER_TAGS . " "
|
|
. "FROM " . DB_T_USER_TAGS . " "
|
|
@@ -419,18 +463,18 @@ class user
|
|
|
db::bind(':id', $_idUser);
|
|
db::bind(':id', $_idUser);
|
|
|
$tmp = db::resultset();
|
|
$tmp = db::resultset();
|
|
|
|
|
|
|
|
- if(isset($tmp[0])){
|
|
|
|
|
|
|
+ if (isset($tmp[0])) {
|
|
|
$return = NULL;
|
|
$return = NULL;
|
|
|
foreach ($tmp as $value) {
|
|
foreach ($tmp as $value) {
|
|
|
- $return .= $value["label"].",";
|
|
|
|
|
|
|
+ $return .= $value["label"] . ",";
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$return = substr($return, 0, -1);
|
|
$return = substr($return, 0, -1);
|
|
|
return $return;
|
|
return $return;
|
|
|
} else {
|
|
} else {
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Récupère les identifiants des tags associés à un utilisateur.
|
|
* Récupère les identifiants des tags associés à un utilisateur.
|
|
@@ -438,7 +482,8 @@ class user
|
|
|
* @param float $_idUser Identifiant de l'utilisateur.
|
|
* @param float $_idUser Identifiant de l'utilisateur.
|
|
|
* @return array|null Liste des identifiants des tags ou NULL si aucun tag.
|
|
* @return array|null Liste des identifiants des tags ou NULL si aucun tag.
|
|
|
*/
|
|
*/
|
|
|
- static public function getIdTags(float $_idUser){
|
|
|
|
|
|
|
+ static public function getIdTags(float $_idUser)
|
|
|
|
|
+ {
|
|
|
db::query("SELECT "
|
|
db::query("SELECT "
|
|
|
. "" . DB_T_USER_TAGS . ".id_tags "
|
|
. "" . DB_T_USER_TAGS . ".id_tags "
|
|
|
. "FROM " . DB_T_USER_TAGS . " "
|
|
. "FROM " . DB_T_USER_TAGS . " "
|
|
@@ -446,7 +491,7 @@ class user
|
|
|
. "ORDER BY " . DB_T_USER_TAGS . ".creer");
|
|
. "ORDER BY " . DB_T_USER_TAGS . ".creer");
|
|
|
db::bind(':id', $_idUser);
|
|
db::bind(':id', $_idUser);
|
|
|
$tmp = db::resultset();
|
|
$tmp = db::resultset();
|
|
|
- if(isset($tmp[0])){
|
|
|
|
|
|
|
+ if (isset($tmp[0])) {
|
|
|
$return = [];
|
|
$return = [];
|
|
|
foreach ($tmp as $value) {
|
|
foreach ($tmp as $value) {
|
|
|
$return[] = $value["id_tags"];
|
|
$return[] = $value["id_tags"];
|
|
@@ -470,12 +515,12 @@ class user
|
|
|
db::bind(':id_user', $_idUser);
|
|
db::bind(':id_user', $_idUser);
|
|
|
db::execute();
|
|
db::execute();
|
|
|
|
|
|
|
|
- if($_tags != NULL){
|
|
|
|
|
|
|
+ if ($_tags != NULL) {
|
|
|
$tags = explode(",", $_tags);
|
|
$tags = explode(",", $_tags);
|
|
|
|
|
|
|
|
$sqlMaj = "";
|
|
$sqlMaj = "";
|
|
|
foreach ($tags as $tag) {
|
|
foreach ($tags as $tag) {
|
|
|
- $sqlMaj .= " (:id_user, ".$tag."),";
|
|
|
|
|
|
|
+ $sqlMaj .= " (:id_user, " . $tag . "),";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$sqlMaj = substr($sqlMaj, 0, -1);
|
|
$sqlMaj = substr($sqlMaj, 0, -1);
|
|
@@ -490,20 +535,21 @@ class user
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Marque un utilisateur comme supprimé.
|
|
* Marque un utilisateur comme supprimé.
|
|
|
*
|
|
*
|
|
|
* @param int $_id Identifiant de l'utilisateur.
|
|
* @param int $_id Identifiant de l'utilisateur.
|
|
|
*/
|
|
*/
|
|
|
- public static function deleteUser(int $_id){
|
|
|
|
|
|
|
+ public static function deleteUser(int $_id)
|
|
|
|
|
+ {
|
|
|
db::query("UPDATE " . DB_T_USER . " SET deleted = 1 WHERE id = :id");
|
|
db::query("UPDATE " . DB_T_USER . " SET deleted = 1 WHERE id = :id");
|
|
|
db::bind(':id', $_id);
|
|
db::bind(':id', $_id);
|
|
|
try {
|
|
try {
|
|
|
db::execute();
|
|
db::execute();
|
|
|
} catch (Exception $ex) {
|
|
} catch (Exception $ex) {
|
|
|
alert::recError("Erreur lors de la suppression");
|
|
alert::recError("Erreur lors de la suppression");
|
|
|
- header("Location: /user-" . $_id .".html");
|
|
|
|
|
|
|
+ header("Location: /user-" . $_id . ".html");
|
|
|
exit();
|
|
exit();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -513,14 +559,15 @@ class user
|
|
|
*
|
|
*
|
|
|
* @param int $_id Identifiant de l'utilisateur.
|
|
* @param int $_id Identifiant de l'utilisateur.
|
|
|
*/
|
|
*/
|
|
|
- public static function restoreUser(int $_id){
|
|
|
|
|
|
|
+ public static function restoreUser(int $_id)
|
|
|
|
|
+ {
|
|
|
db::query("UPDATE " . DB_T_USER . " SET deleted = 0 WHERE id = :id");
|
|
db::query("UPDATE " . DB_T_USER . " SET deleted = 0 WHERE id = :id");
|
|
|
db::bind(':id', $_id);
|
|
db::bind(':id', $_id);
|
|
|
try {
|
|
try {
|
|
|
db::execute();
|
|
db::execute();
|
|
|
} catch (Exception $ex) {
|
|
} catch (Exception $ex) {
|
|
|
alert::recError("Erreur lors de la restauration");
|
|
alert::recError("Erreur lors de la restauration");
|
|
|
- header("Location: /user-" . $_id .".html");
|
|
|
|
|
|
|
+ header("Location: /user-" . $_id . ".html");
|
|
|
exit();
|
|
exit();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -530,7 +577,8 @@ class user
|
|
|
*
|
|
*
|
|
|
* @return bool TRUE si la double authentification est activée, FALSE sinon.
|
|
* @return bool TRUE si la double authentification est activée, FALSE sinon.
|
|
|
*/
|
|
*/
|
|
|
- static public function checkSecur(){
|
|
|
|
|
|
|
+ static public function checkSecur()
|
|
|
|
|
+ {
|
|
|
db::query("SELECT googleAuthenticator FROM " . DB_T_USER . " WHERE id = :id");
|
|
db::query("SELECT googleAuthenticator FROM " . DB_T_USER . " WHERE id = :id");
|
|
|
db::bind(':id', session::getId());
|
|
db::bind(':id', session::getId());
|
|
|
return db::single()["googleAuthenticator"] == 1 ? TRUE : FALSE;
|
|
return db::single()["googleAuthenticator"] == 1 ? TRUE : FALSE;
|
|
@@ -539,10 +587,11 @@ class user
|
|
|
/**
|
|
/**
|
|
|
* Affiche un message de sécurité si la double authentification n'est pas activée.
|
|
* Affiche un message de sécurité si la double authentification n'est pas activée.
|
|
|
*/
|
|
*/
|
|
|
- static public function printIsSecur(){
|
|
|
|
|
- if(ALERT_AUTHENTICATOR == TRUE){
|
|
|
|
|
|
|
+ static public function printIsSecur()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (ALERT_AUTHENTICATOR == TRUE) {
|
|
|
$_SESSION["CALLOUT"] ??= 0;
|
|
$_SESSION["CALLOUT"] ??= 0;
|
|
|
- if(self::checkSecur() == FALSE AND $_SESSION["CALLOUT"] < NB_ALERT_AUTHENTICATOR){
|
|
|
|
|
|
|
+ if (self::checkSecur() == FALSE and $_SESSION["CALLOUT"] < NB_ALERT_AUTHENTICATOR) {
|
|
|
$callout = [
|
|
$callout = [
|
|
|
"type" => "danger",
|
|
"type" => "danger",
|
|
|
"size" => "tiny",
|
|
"size" => "tiny",
|
|
@@ -554,4 +603,102 @@ class user
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Vérifie si le 2FA est en attente de validation pour un utilisateur.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int $_id Identifiant de l'utilisateur.
|
|
|
|
|
+ * @return bool TRUE si le 2FA est en attente de validation, FALSE sinon.
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function is2FAPending(int $_id): bool
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ db::query("SELECT googleAuthenticatorPending FROM " . DB_T_USER . " WHERE id = :id");
|
|
|
|
|
+ db::bind(':id', $_id);
|
|
|
|
|
+ $result = db::single();
|
|
|
|
|
+ return isset($result["googleAuthenticatorPending"]) && $result["googleAuthenticatorPending"] == 1;
|
|
|
|
|
+ } catch (Exception $ex) {
|
|
|
|
|
+ // La colonne n'existe pas encore, retourner false
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Définit le 2FA en mode pending (en attente de validation du premier code).
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int $_id Identifiant de l'utilisateur.
|
|
|
|
|
+ * @return bool TRUE si la mise à jour est réussie, FALSE sinon.
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function set2FAPending(int $_id): bool
|
|
|
|
|
+ {
|
|
|
|
|
+ db::query("UPDATE " . DB_T_USER . " SET googleAuthenticatorPending = 1, googleAuthenticator = 0 WHERE id = :id");
|
|
|
|
|
+ db::bind(':id', $_id);
|
|
|
|
|
+ try {
|
|
|
|
|
+ db::execute();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (Exception $ex) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Valide le code TOTP et active définitivement le 2FA.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int $_id Identifiant de l'utilisateur.
|
|
|
|
|
+ * @param string $_code Code TOTP à vérifier.
|
|
|
|
|
+ * @return array Résultat de la validation avec status et message.
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function validate2FAActivation(int $_id, string $_code): array
|
|
|
|
|
+ {
|
|
|
|
|
+ // Récupérer le secret de l'utilisateur
|
|
|
|
|
+ $secret = self::getMyGoogleAuthenticator($_id);
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($secret)) {
|
|
|
|
|
+ return [
|
|
|
|
|
+ "status" => "error",
|
|
|
|
|
+ "message" => "Aucun secret Google Authenticator configuré."
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Vérifier le code TOTP
|
|
|
|
|
+ if (googleAuthenticator::verifyCode($secret, $_code, 1)) {
|
|
|
|
|
+ // Code valide, activer le 2FA et supprimer le pending
|
|
|
|
|
+ db::query("UPDATE " . DB_T_USER . " SET googleAuthenticator = 1, googleAuthenticatorPending = 0 WHERE id = :id");
|
|
|
|
|
+ db::bind(':id', $_id);
|
|
|
|
|
+ try {
|
|
|
|
|
+ db::execute();
|
|
|
|
|
+ return [
|
|
|
|
|
+ "status" => "success",
|
|
|
|
|
+ "message" => "La double authentification a été activée avec succès."
|
|
|
|
|
+ ];
|
|
|
|
|
+ } catch (Exception $ex) {
|
|
|
|
|
+ return [
|
|
|
|
|
+ "status" => "error",
|
|
|
|
|
+ "message" => "Erreur lors de l'activation de la double authentification."
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return [
|
|
|
|
|
+ "status" => "error",
|
|
|
|
|
+ "message" => "Code invalide. Veuillez réessayer."
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Annule le mode pending du 2FA.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int $_id Identifiant de l'utilisateur.
|
|
|
|
|
+ * @return bool TRUE si l'annulation est réussie, FALSE sinon.
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function cancel2FAPending(int $_id): bool
|
|
|
|
|
+ {
|
|
|
|
|
+ db::query("UPDATE " . DB_T_USER . " SET googleAuthenticatorPending = 0 WHERE id = :id");
|
|
|
|
|
+ db::bind(':id', $_id);
|
|
|
|
|
+ try {
|
|
|
|
|
+ db::execute();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (Exception $ex) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|