1
0
mirror of https://git.cant.at/Madeorsk/PollVerlaine synced 2024-11-22 08:54:33 +01:00

WIP: DELETE Redirect on error

This commit is contained in:
Tagadda 2018-08-13 16:22:24 +02:00
parent 9469ffb88b
commit a0333c7065

View File

@ -95,17 +95,28 @@ Flight::route("GET|DELETE /polls/@id:[a-fA-F0-9]+/@token:[a-fA-F0-9]+", function
$poll = Poll::load_poll($id); $poll = Poll::load_poll($id);
if ($poll) if ($poll)
{ {
if ($poll->delete_token !== $token) if (Flight::request()->type === "application/json")
Flight::halt(401, "<h1>401 Unauthorized</h1><h3>Invalid token.</h3>"); {
if ($poll->delete_token === $token)
{
$poll->delete(); $poll->delete();
if (Flight::request()->type === "application/json")
Flight::json(format_poll($poll), 204); Flight::json(format_poll($poll), 204);
}
else
Flight::halt(401, "<h1>401 Unauthorized</h1><h3>Invalid token.</h3>");
}
else else
{ {
if ($poll->delete_token === $token)
{
$poll->delete();
Flight::redirect('/', 204); Flight::redirect('/', 204);
} }
else
Flight::redirect('/', 401);
}
} }
else else
Flight::notFound(); Flight::notFound();