From 0f54da2c648a5913f6ed282f39dc7d6a62ef37da Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 2 Feb 2025 11:06:04 +0200 Subject: feat(views/list): Fully implement list deletion --- controllers/list.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'controllers/list.php') diff --git a/controllers/list.php b/controllers/list.php index 07db6c5..c2e72a0 100644 --- a/controllers/list.php +++ b/controllers/list.php @@ -80,3 +80,36 @@ function on_put() { header('Location: /list/' . $list->LID); exit(); } + +function on_delete() { + global $TOKEN; + global $METHOD; + global $list_status; + + $list = null; + try { + $list = Database\ArchiveList::fromDB($METHOD['lid']); + } + catch(Exception $e) { + $list_status = "This list doesn't exist!"; + return; + } + + try { + $user = Database\Cookie::fromDB($TOKEN); + $author = Database\User::fromDBuid($list->AuthorUID); + if ($author->UID !== $user->UID) { + $list_status = "You're not the owner of this list! You have no permission to delete it!"; + return; + } + } + catch(Exception $e) { + $list_status = "Either your cookie is invalid or the author of this list has deleted their account!"; + return; + } + + $list->delete(); + + header('Location: /'); + exit(); +} -- cgit v1.2.3