From ae1ce7ec1014faaca9e5cb480e4fd8219e4aa866 Mon Sep 17 00:00:00 2001
From: Eunice Sarah Siregar <13521013@mahasiswa.itb.ac.id>
Date: Fri, 6 Oct 2023 23:00:43 +0700
Subject: [PATCH] Revert "add: delete profile"

This reverts commit 09cd7cafbc4b4dc57351969c7823ffd384ebbb25.
---
 src/app/components/profile/index.php | 37 +++++------------------
 src/public/js/profile.js             | 45 ----------------------------
 2 files changed, 8 insertions(+), 74 deletions(-)

diff --git a/src/app/components/profile/index.php b/src/app/components/profile/index.php
index 1b8a948..ddc5425 100644
--- a/src/app/components/profile/index.php
+++ b/src/app/components/profile/index.php
@@ -14,34 +14,12 @@
         $result = $mysqli->query($sql);
         $user = $result->fetch_assoc();
     }
-
-    // Fungsi untuk menghapus akun
-    function deleteAccount() {
+    if (isset($_POST['update_profile'])) {
         $servername = "db";
         $username = "php_docker";
         $password = "password";
         $dbname = "php_docker";
         $conn = mysqli_connect($servername, $username, $password, $dbname);
-
-        if (!$conn) {
-            die("Koneksi ke database gagal: " . mysqli_connect_error());
-        }
-
-        $user_id = $_SESSION["user_id"];
-
-        $deleteUserQuery = "DELETE FROM user WHERE user_id = '$user_id'";
-        if (mysqli_query($conn, $deleteUserQuery)) {
-            
-            session_destroy();
-            header("Location: /?login");
-            exit;
-        } else {
-            echo "Error: " . mysqli_error($conn);
-        }
-    }
-
-    if (isset($_POST['update_profile'])) {
-        $conn = mysqli_connect($servername, $username, $password, $dbname);
         if (!$conn) {
             die("Koneksi ke database gagal: " . mysqli_connect_error());
         }
@@ -63,19 +41,20 @@
             $newPhone = mysqli_real_escape_string($conn, $_POST['user_phone']);
         }
         
-
+   
+        // Validasi input sesuai kebutuhan Anda
+    
+        // Update data pengguna di database
         $updateQuery = "UPDATE user SET user_name = '$newName', user_email = '$newEmail', user_phone = '$newPhone' WHERE user_id = '$user_id'";
         if (mysqli_query($conn, $updateQuery)) {
+            // Redirect atau berikan pesan sukses, misalnya:
             header("Location: /?profile");
             exit;
         } else {
+            // Handle kesalahan jika gagal melakukan pembaruan
             echo "Error: " . mysqli_error($conn);
         }
     }
-
-    if (isset($_POST['delete_account'])) {
-        deleteAccount();
-    }
 ?>
 
 <!DOCTYPE html>
@@ -112,7 +91,7 @@
                 <input type="text" id="user_phone" name="user_phone" value="<?= $user["user_phone"] ?>" disabled>
                 <button class="edit-button" id="edit-phone-button" type="button">Edit</button>
                 </div>
-                <button type="submit" id="delete_account" name="delete_account">Delete Account</button>
+
                 <button type="submit" id="update_profile" name="update_profile" style="display: none;">Update</button>
 
             </form>
diff --git a/src/public/js/profile.js b/src/public/js/profile.js
index c750ac7..d1d8051 100644
--- a/src/public/js/profile.js
+++ b/src/public/js/profile.js
@@ -39,49 +39,4 @@ document.addEventListener("DOMContentLoaded", function () {
             updateProfileButton.style.display = "block";
         }
     }
-    // profile.js
-
-// ...
-const deleteAccountButton = document.getElementById("delete_account_button");
-
-// Tambahkan event listener untuk tombol "Delete Account"
-deleteAccountButton.addEventListener("click", function () {
-    const confirmDelete = confirm("Anda yakin ingin menghapus akun Anda?");
-
-    if (confirmDelete) {
-        // Redirect atau lakukan penghapusan akun di sini
-
-        deleteAccount();
-    }
-});
-
-function deleteAccount() {
-    // Lakukan permintaan AJAX atau penghapusan akun ke server di sini
-    // Setelah berhasil menghapus akun, lakukan langkah-langkah berikut:
-
-    // 1. Hapus semua session
-    // 2. Lakukan logout
-    // 3. Redirect ke halaman lain (misalnya halaman login)
-    
-    // Contoh penghapusan semua session:
-    fetch("/logout.php", {
-        method: "POST",
-        headers: {
-            "Content-Type": "application/json",
-        },
-    })
-    .then(function(response) {
-        if (response.ok) {
-            // Logout berhasil, arahkan ke halaman login atau halaman lain
-            window.location.href = "/login.php"; // Ganti dengan halaman yang sesuai
-        } else {
-            // Handle kesalahan jika logout gagal
-            console.error("Gagal logout");
-        }
-    })
-    .catch(function(error) {
-        console.error("Terjadi kesalahan:", error);
-    });
-}
-
 });
-- 
GitLab