Переглянути джерело

Ajout de log et modification suppression user

stany.ferer 2 роки тому
батько
коміт
0a34f1cd7c

+ 3 - 3
core/class/historique.class.php

@@ -2,7 +2,7 @@
 
 class historique
 {
-    private static function recRef(string $_name) {
+    public static function recRef(string $_name) {
         db::query("INSERT IGNORE INTO " . DB_T_HISTORIQUE_REF . " (name) VALUES (:name)");
         db::bind(':name', $_name);
         try {
@@ -12,7 +12,7 @@ class historique
         }
     }
 
-    private static function getIdRef(string $_name) {
+    public static function getIdRef(string $_name) {
         db::query("SELECT id FROM " . DB_T_HISTORIQUE_REF . " WHERE name = :name");
         db::bind(':name', $_name);
         return db::single()["id"];
@@ -136,7 +136,7 @@ class historique
         }
     }
 
-    private static function add(array $_input){
+    public static function add(array $_input){
         db::query("INSERT INTO " . DB_T_HISTORIQUE . " (idType, idUser, idPage, log) VALUES (:idType, :idUser, :idPage, :log)");
         db::bind(':idType', $_input["idType"]);
         db::bind(':idUser', $_input["idUser"]);

+ 11 - 4
core/class/user.class.php

@@ -39,7 +39,8 @@ class user {
                 . "" . DB_T_USER . ".id_type, "
                 . "" . DB_T_USER_TYPE . ".type "
                 . "FROM " . DB_T_USER . " "
-                . "INNER JOIN " . DB_T_USER_TYPE . " ON " . DB_T_USER . ".id_type = " . DB_T_USER_TYPE . ".id");
+                . "INNER JOIN " . DB_T_USER_TYPE . " ON " . DB_T_USER . ".id_type = " . DB_T_USER_TYPE . ".id "
+                . "WHERE " . DB_T_USER . ".deleted = 0");
         return db::resultset();
     }
 
@@ -55,7 +56,7 @@ class user {
     public static function connect(array $_input) {
         $return = NULL;
         if (isset($_input["email"]) AND isset($_input["password"])) {
-            db::query("SELECT id, email, password, prenom, nom, id_type, googleAuthenticator, googleAuthenticatorSecret, actif FROM " . DB_T_USER . " WHERE email = :email");
+            db::query("SELECT id, email, password, prenom, nom, id_type, googleAuthenticator, googleAuthenticatorSecret, actif FROM " . DB_T_USER . " WHERE email = :email AND deleted = 0");
             db::bind(':email', $_input["email"]);
             $row = db::single();
 
@@ -177,9 +178,15 @@ class user {
     }
     
     public static function deleteUser(int $_id){
-        db::query("DELETE FROM ". DB_T_USER ." WHERE id = :id");
+        db::query("UPDATE " . DB_T_USER . " SET deleted = 1 WHERE id = :id");
         db::bind(':id', $_id);
-        return db::execute();
+        try {
+            db::execute();
+        } catch (Exception $ex) {
+            alert::recError("Erreur lors de la suppression");
+            header("Location: /user-" . $_id .".html");
+            exit();
+        }
     }
 
 }

+ 12 - 1
core/submit/cms.login.php

@@ -1,7 +1,18 @@
 <?php
 
 if (core::ifPost("from") AND core::getPost("from") == "login") {
-    user::connect(core::getPost());
+    $connect = user::connect(core::getPost());
+
+    if($connect == TRUE){
+        historique::recRef($_SERVER["REQUEST_URI"]);
+        historique::add(array(
+            "idType" => historique::getIdRef("CONNEXION"),
+            "idUser" => session::getId(),
+            "idPage" => historique::getIdRef($_SERVER["REQUEST_URI"]),
+            "log" => $_SERVER['REMOTE_ADDR']
+        ));
+    }
+    
     header("Location: /");
     exit();
 } else {

+ 9 - 0
core/submit/cms.parametres-add-backup.php

@@ -3,6 +3,15 @@
 if (core::ifGet("from")) {
     backup::create();
     file::cleanFilesByOrder(DIR_BACKUP, BACKUP_LIMIT);
+
+    historique::recRef("/parametres.html");
+    historique::add(array(
+        "idType" => historique::getIdRef("ACTION"),
+        "idUser" => session::getId(),
+        "idPage" => historique::getIdRef("/parametres.html"),
+        "log" => "Création d'un backup"
+    ));
+
     header("Location: /parametres.html");
     exit();
 } else {

+ 18 - 0
core/submit/cms.parametres-debug-activation.php

@@ -2,9 +2,27 @@
 if(core::ifGet("actif")){
     if(core::getGet("actif") == "true"){
         core::addFileDebug();
+
+        historique::recRef("/parametres.html");
+        historique::add(array(
+            "idType" => historique::getIdRef("ACTION"),
+            "idUser" => session::getId(),
+            "idPage" => historique::getIdRef("/parametres.html"),
+            "log" => "Mode debug : Activation"
+        ));
+
         alert::recSuccess("Le mode debug est activé");
     } else {
         core::removeFileDebug();
+
+        historique::recRef("/parametres.html");
+        historique::add(array(
+            "idType" => historique::getIdRef("ACTION"),
+            "idUser" => session::getId(),
+            "idPage" => historique::getIdRef("/parametres.html"),
+            "log" => "Mode debug : Activation"
+        ));
+
         alert::recSuccess("Le mode debug est déactivé");
     }
 }

+ 18 - 2
core/submit/cms.parametres-maintenance-activation.php

@@ -2,11 +2,27 @@
 if(core::ifGet("actif")){
     if(core::getGet("actif") == "true"){
         core::addFileMaintenance();
-        echo json_encode(array("1"));
+
+        historique::recRef("/parametres.html");
+        historique::add(array(
+            "idType" => historique::getIdRef("ACTION"),
+            "idUser" => session::getId(),
+            "idPage" => historique::getIdRef("/parametres.html"),
+            "log" => "Mode maintenance : Activation"
+        ));
+
         alert::recSuccess("Le mode maintenance est activé");
     } else {
         core::removeFileMaintenance();
-        echo json_encode(array("0"));
+
+        historique::recRef("/parametres.html");
+        historique::add(array(
+            "idType" => historique::getIdRef("ACTION"),
+            "idUser" => session::getId(),
+            "idPage" => historique::getIdRef("/parametres.html"),
+            "log" => "Mode maintenance : Désactivation"
+        ));
+
         alert::recSuccess("Le mode maintenance est déactivé");
     }
 }

+ 9 - 0
core/submit/cms.parametres-reset-datas.php

@@ -2,6 +2,15 @@
 
 if((ENVIRONNEMENT == "DEV" OR ENVIRONNEMENT == "PREPROD")) {
     core::resetDatas();
+
+    historique::recRef("/parametres.html");
+    historique::add(array(
+        "idType" => historique::getIdRef("ACTION"),
+        "idUser" => session::getId(),
+        "idPage" => historique::getIdRef("/parametres.html"),
+        "log" => "Nettoyage de la base de données"
+    ));
+
     alert::recSuccess("Le nettoyage des données a bien été réalisé");
     header("Location: /parametres.html");
     exit();

+ 9 - 0
core/submit/cms.user-delete.php

@@ -3,6 +3,15 @@
 if(core::ifGet("id")) {
     user::deleteUser(core::getGet("id"));
     json::create("users");
+
+    historique::recRef("/user-".core::getGet("id").".html");
+    historique::add(array(
+        "idType" => historique::getIdRef("ACTION"),
+        "idUser" => session::getId(),
+        "idPage" => historique::getIdRef("/user-".core::getGet("id").".html"),
+        "log" => "Suppression d'un compte"
+    ));
+
     alert::recSuccess("Le compte vient d'être supprimé");
 }
 

+ 18 - 0
core/submit/cms.user.php

@@ -4,11 +4,29 @@ if (core::ifPost("from") AND core::getPost("from") == "user") {
     
     if(core::getPost("id") == "add"){
         user::add_user(core::getPost());
+
+        historique::recRef("/user-".user::lastUser().".html");
+        historique::add(array(
+            "idType" => historique::getIdRef("ACTION"),
+            "idUser" => session::getId(),
+            "idPage" => historique::getIdRef("/user-".user::lastUser().".html"),
+            "log" => "Création du compte"
+        ));
+
         header("Location: /user-" . user::lastUser() . ".html");
         exit();
         
     } else {
         user::maj_user(core::getPost());
+
+        historique::recRef("/user-".core::getPost("id").".html");
+        historique::add(array(
+            "idType" => historique::getIdRef("ACTION"),
+            "idUser" => session::getId(),
+            "idPage" => historique::getIdRef("/user-".core::getPost("id").".html"),
+            "log" => "Modification du compte"
+        ));
+
         if(core::getPost("id") == session::getId()){
             header("Location: /user.html");
         } else {

+ 3 - 0
core/views/pages/cms.parametres-users.php

@@ -22,9 +22,12 @@
                     <th data-sortable="true" data-field="id" data-filter-control="input">#</th>
                     <th data-sortable="true" data-field="nom" data-filter-control="input">Nom</th>
                     <th data-sortable="true" data-field="prenom" data-filter-control="input">Prénom</th>
+                    <th data-sortable="true" data-field="email" data-filter-control="select">Email</th>
+                    <th data-sortable="true" data-field="googleAuthenticator" data-filter-control="select">OTP</th>
                     <th data-sortable="true" data-field="type" data-filter-control="select">Type de compte</th>
                     <th data-sortable="true" data-field="cree" data-filter-control="input">Créé</th>
                     <th data-sortable="true" data-field="last_connect" data-filter-control="input">Dernière connexion</th>
+                    <th data-sortable="true" data-field="actif" data-filter-control="select">Actif</th>
                     <th data-field="id" data-formatter="selectUser"></th>
                 </tr>
             </thead>

+ 3 - 0
core/views/pages/cms.user.php

@@ -146,5 +146,8 @@ if(core::ifGet("add")) {
         <?php endif; ?>
     
     <input class="btn btn-primary btn-lg" style="width: 100%" type="submit" value="<?php echo $submit ?>">
+
+    <br />
+    <br />
     
 </form>