From a0333c7065746e00e38762afab41b8721aba7c9c Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Mon, 13 Aug 2018 16:22:24 +0200 Subject: [PATCH] WIP: DELETE Redirect on error --- index.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index 0916b61..fb57ece 100644 --- a/index.php +++ b/index.php @@ -95,16 +95,27 @@ Flight::route("GET|DELETE /polls/@id:[a-fA-F0-9]+/@token:[a-fA-F0-9]+", function $poll = Poll::load_poll($id); if ($poll) { - if ($poll->delete_token !== $token) - Flight::halt(401, "

401 Unauthorized

Invalid token.

"); - - $poll->delete(); - if (Flight::request()->type === "application/json") - Flight::json(format_poll($poll), 204); + { + if ($poll->delete_token === $token) + { + $poll->delete(); + + Flight::json(format_poll($poll), 204); + } + else + Flight::halt(401, "

401 Unauthorized

Invalid token.

"); + } else { - Flight::redirect('/', 204); + if ($poll->delete_token === $token) + { + $poll->delete(); + + Flight::redirect('/', 204); + } + else + Flight::redirect('/', 401); } } else