From 29337b30b7071cff678a7be54161507f3eb278be Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 15 May 2025 00:07:41 +0500 Subject: feat: pfp, banner, badge deletion buttons --- public/account/delete.php | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'public/account/delete.php') diff --git a/public/account/delete.php b/public/account/delete.php index 99aebe5..ec8c040 100644 --- a/public/account/delete.php +++ b/public/account/delete.php @@ -9,28 +9,42 @@ if (!isset($_SESSION["user_id"])) { exit; } -$id = $_SESSION["user_id"]; - $db = new PDO(DB_URL, DB_USER, DB_PASS); -$db->prepare("DELETE FROM users WHERE id = ?")->execute([$id]); -session_unset(); -session_destroy(); +$id = $_SESSION["user_id"]; -setcookie("secret_key", "", time() - 1000); +$profile = ($_GET["profile"] ?? "false") == "true"; +$pfp = ($_GET["pfp"] ?? "false") == "true"; +$banner = ($_GET["banner"] ?? "false") == "true"; +$badge = ($_GET["badge"] ?? "false") == "true"; + +if ($pfp || $profile) { + $path = "../static/userdata/avatars/$id"; + if (is_dir($path)) { + array_map("unlink", glob("$path/*.*")); + rmdir($path); + } +} -$db = null; +if ($banner || $profile) { + $path = "../static/userdata/banners/$id"; + if (is_dir($path)) { + array_map("unlink", glob("$path/*.*")); + rmdir($path); + } +} -$path = "../static/userdata/avatars/$id"; -if (is_dir($path)) { - array_map("unlink", glob("$path/*.*")); - rmdir($path); +if ($badge || $profile) { + $db->prepare("DELETE FROM user_badges WHERE user_id = ?")->execute([$id]); } -$path = "../static/userdata/banners/$id"; -if (is_dir($path)) { - array_map("unlink", glob("$path/*.*")); - rmdir($path); +if ($profile) { + $db->prepare("DELETE FROM users WHERE id = ?")->execute([$id]); + + session_unset(); + session_destroy(); + + setcookie("secret_key", "", time() - 1000); } header("Location: /account"); \ No newline at end of file -- cgit v1.2.3