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 +++++++++++++++++++++++++++++--------------- public/account/index.php | 42 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 63 insertions(+), 23 deletions(-) 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 diff --git a/public/account/index.php b/public/account/index.php index 6cf3fc7..2b9e790 100644 --- a/public/account/index.php +++ b/public/account/index.php @@ -123,40 +123,67 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {

Profile

Profile picture

'; } else { echo "

You don't have profile picture

"; } ?> - +
+ + + + Remove profile picture + + +

Profile banner

'; } else { echo "

You don't have profile banner

"; } ?> - +
+ + + + Remove banner + + +

Personal badge

prepare("SELECT badge_id FROM user_badges WHERE user_id = ?"); $stmt->execute([$_SESSION["user_id"]]); + $has_badge = false; + if ($row = $stmt->fetch()) { echo '
'; echo ''; echo ''; echo ''; echo '
'; + $has_badge = true; } else { echo "

You don't have personal badge

"; } ?> - +
+ + + + Remove badge + + +

Username

"> @@ -253,9 +280,8 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { -
- -
+ Delete + me -- cgit v1.2.3