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 +++++++++++++++++++++++++++++++++ models/archivelist.php | 7 +++++++ views/global/router.php | 1 + views/list/delete/index.php | 40 ++++++++++++++++++++++++++++++++++++++++ views/list/delete/meta.php | 4 ++++ 5 files changed, 85 insertions(+) create mode 100644 views/list/delete/index.php create mode 100644 views/list/delete/meta.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(); +} diff --git a/models/archivelist.php b/models/archivelist.php index bf734e0..7a76475 100644 --- a/models/archivelist.php +++ b/models/archivelist.php @@ -49,4 +49,11 @@ class ArchiveList extends Table { "LID = \"$this->LID\"" ); } + + function delete() { + Table::_delete( + 'ArchiveLists', + "LID = \"$this->LID\"" + ); + } } diff --git a/views/global/router.php b/views/global/router.php index ea3799f..18adfca 100644 --- a/views/global/router.php +++ b/views/global/router.php @@ -30,6 +30,7 @@ function route_view() { case '/list/update': return '/list/update'; case '/list/new': return '/list/new'; case '/list/add': return '/list/add'; + case '/list/delete': return '/list/delete'; } switch ($root) { diff --git a/views/list/delete/index.php b/views/list/delete/index.php new file mode 100644 index 0000000..7d5bf5b --- /dev/null +++ b/views/list/delete/index.php @@ -0,0 +1,40 @@ +AuthorUID); + $user = Database\Cookie::fromDB($TOKEN); + } + catch(Exception $e) {} +?> + +UID === $author->UID): ?> + +

Are you sure you want to delete Username ?>'s "Name ?>"?

+ +
+ + + +

+ Error: +

+ + + + + +
+ + +

No list with identifier exists!

+ + +

You have no permission to delete Username ?>'s "Name ?>"!

+ + diff --git a/views/list/delete/meta.php b/views/list/delete/meta.php new file mode 100644 index 0000000..2e07b80 --- /dev/null +++ b/views/list/delete/meta.php @@ -0,0 +1,4 @@ +