summaryrefslogtreecommitdiff
path: root/account/delete.php
blob: 0a0bbb6f144f48d9599cef3a9c13efd55d268b3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
include "{$_SERVER['DOCUMENT_ROOT']}/lib/utils.php";
include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/config.php";

session_start();

if (!isset($_SESSION["user_id"])) {
    header("Location: /account");
    exit;
}

$db = new PDO(CONFIG['database']['url'], CONFIG['database']['user'], CONFIG['database']['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");