Kaynağa Gözat

Fixe Profil et Add Code auto

stany.ferer 2 yıl önce
ebeveyn
işleme
e70173b8ee
2 değiştirilmiş dosya ile 24 ekleme ve 12 silme
  1. 15 1
      core/class/user.class.php
  2. 9 11
      core/views/pages/cms.user.php

+ 15 - 1
core/class/user.class.php

@@ -130,6 +130,7 @@ class user {
     }
     
     public static function maj_user(array $_input){
+
         if($_input["password"] != ""){
             db::query("UPDATE " . DB_T_USER . " SET password = :password WHERE id = :id");
             db::bind(':password', md5($_input["password"]));
@@ -137,7 +138,20 @@ class user {
             try {
                 db::execute();
             } catch (Exception $ex) {
-                alert::recError("Erreur lors de la modification de l'utilisateur");
+                alert::recError("Erreur lors de la modification du mot de passe");
+                header("Location: /user-" . $_input["id"] .".html");
+                exit();
+            }
+        }
+
+        if(self::getMyGoogleAuthenticator($_input["id"]) == NULL){
+            db::query("UPDATE " . DB_T_USER . " SET googleAuthenticatorSecret = :googleAuthenticatorSecret WHERE id = :id");
+            db::bind(':googleAuthenticatorSecret', googleAuthenticator::createSecret());
+            db::bind(':id', $_input["id"]);
+            try {
+                db::execute();
+            } catch (Exception $ex) {
+                alert::recError("Erreur lors de la création du token de Google Authenticator");
                 header("Location: /user-" . $_input["id"] .".html");
                 exit();
             }

+ 9 - 11
core/views/pages/cms.user.php

@@ -5,20 +5,18 @@ if(core::ifGet("add")) {
     $titre = "Ajouter un profil";
 } else {
     
-    $databaseUser = new user();
-    
-    if(core::ifGet("id") and session::getId() != core::ifGet("id")){
-        $user = $databaseUser->getUserById(core::getGet("id"));
-        $submit = "Modifier ce profil";
-        $titre = "Fiche de " . $user["prenom"] . " " . $user["nom"];
-        $protect = 0;
-    } else {
-        $user = $databaseUser->getUserById(session::getId());
+    if(core::ifGet("id") == FALSE OR (core::ifGet("id") AND session::getId() == core::getGet("id"))){
+        $user = user::getUserById(session::getId());
         $submit = "Modifier votre profil";
         $titre = "Votre fiche de profil";
         $protect = 1;
-    }
-    
+    } else {
+        $user = user::getUserById(core::getGet("id"));
+        $submit = "Modifier ce profil";
+        $titre = "Fiche de " . $user["prenom"] . " " . $user["nom"];
+        $protect = 0;
+    } 
+
     $id_form = '<input type="hidden" name="id" value="' . $user["id"] . '">';
 }