summaryrefslogtreecommitdiff
path: root/public/account/delete.php
blob: af8a093a6aa7a37b89a10a7b9d53bfa950c4e661 (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
<?php
include "../../src/utils.php";

session_start();

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

$id = $_SESSION["user_id"];

$db = new SQLite3("../../database.db");

$stmt = $db->prepare("UPDATE emotes SET uploaded_by = NULL WHERE uploaded_by = :id");
$stmt->bindValue(":id", $id);
$stmt->execute();

$stmt = $db->prepare("DELETE FROM connections WHERE user_id = :id");
$stmt->bindValue(":id", $id);
$stmt->execute();

$stmt = $db->prepare("DELETE FROM users WHERE id = :id");
$stmt->bindValue(":id", $id);
$stmt->execute();

session_unset();
session_destroy();

setcookie("secret_key", "", time() - 1000);

$db->close();

$path = "../static/userdata/avatars/$id";
if (is_file($path)) {
    unlink($path);
}

header("Location: /account");