summaryrefslogtreecommitdiff
path: root/account/delete.php
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-12-08 21:53:36 +0500
committerilotterytea <iltsu@alright.party>2025-12-08 21:53:36 +0500
commit57472eab3c7b035392c6a5aa240593ecaa7d1ccf (patch)
tree9da30829290f225be2dab3d383549cbfda82ed19 /account/delete.php
parent6541d0f3888862ab049055fd418b700f73eed367 (diff)
upd: moved all /public/ files to the root folder
Diffstat (limited to 'account/delete.php')
-rw-r--r--account/delete.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/account/delete.php b/account/delete.php
new file mode 100644
index 0000000..ec8c040
--- /dev/null
+++ b/account/delete.php
@@ -0,0 +1,50 @@
+<?php
+include "../../src/utils.php";
+include_once "../../src/config.php";
+
+session_start();
+
+if (!isset($_SESSION["user_id"])) {
+ header("Location: /account");
+ exit;
+}
+
+$db = new PDO(DB_URL, DB_USER, DB_PASS);
+
+$id = $_SESSION["user_id"];
+
+$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);
+ }
+}
+
+if ($banner || $profile) {
+ $path = "../static/userdata/banners/$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]);
+}
+
+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