Replace Template::Emit...() functions with more generic function

This commit is contained in:
Alex Cabal 2024-12-18 13:14:16 -06:00
parent f449c024ea
commit 806939ca49
40 changed files with 86 additions and 68 deletions

View file

@ -33,19 +33,39 @@ class Template{
} }
} }
public static function Emit403(): void{ /**
http_response_code(Enums\HttpCode::Forbidden->value); * Exit the script while outputting the given HTTP code.
include(WEB_ROOT . '/403.php'); *
* @param bool $showPage If **`TRUE`**, show a special page given the HTTP code (like a 404 page).
*
* @return never
*/
public static function ExitWithCode(Enums\HttpCode $httpCode, bool $showPage = true, Enums\HttpRequestType $requestType = Enums\HttpRequestType::Web): void{
http_response_code($httpCode->value);
if($requestType == Enums\HttpRequestType::Web && $showPage){
switch($httpCode){
case Enums\HttpCode::Forbidden:
include(WEB_ROOT . '/403.php');
break;
case Enums\HttpCode::NotFound:
include(WEB_ROOT . '/404.php');
break;
}
}
exit(); exit();
} }
public static function Emit404(): void{ /**
http_response_code(Enums\HttpCode::NotFound->value); * Redirect the user to the login page.
include(WEB_ROOT . '/404.php'); *
exit(); * @param bool $redirectToDestination After login, redirect the user to the page they came from.
} * @param ?string $destinationUrl If `$redirectToDestination` is **`TRUE`**, redirect to this URL instead of hte page they came from.
*
public static function RedirectToLogin(bool $redirectToDestination = true, string $destinationUrl = null): void{ * @return never
*/
public static function RedirectToLogin(bool $redirectToDestination = true, ?string $destinationUrl = null): void{
if($redirectToDestination){ if($redirectToDestination){
if($destinationUrl === null){ if($destinationUrl === null){
$destinationUrl = $_SERVER['SCRIPT_URL']; $destinationUrl = $_SERVER['SCRIPT_URL'];

View file

@ -41,9 +41,7 @@ try{
$ebook->CreateOrUpdate(); $ebook->CreateOrUpdate();
// If there was an `EbookPlaceholder` for this ebook, delete it. // If there was an `EbookPlaceholder` for this ebook, delete it.
if($ebook->EbookPlaceholder !== null){ $ebook->EbookPlaceholder?->Delete();
$ebook->EbookPlaceholder->Delete();
}
// If there was a `Project` for this ebook, mark it as completed. // If there was a `Project` for this ebook, mark it as completed.
if($ebook->ProjectInProgress !== null){ if($ebook->ProjectInProgress !== null){

View file

@ -21,7 +21,7 @@ try{
} }
} }
catch(Exceptions\ArtistNotFoundException){ catch(Exceptions\ArtistNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => 'Artwork by ' . $artworks[0]->Artist->Name, 'css' => ['/css/artwork.css']]) ?> ?><?= Template::Header(['title' => 'Artwork by ' . $artworks[0]->Artist->Name, 'css' => ['/css/artwork.css']]) ?>
<main class="artworks"> <main class="artworks">

View file

@ -26,13 +26,13 @@ try{
} }
} }
catch(Exceptions\ArtworkNotFoundException){ catch(Exceptions\ArtworkNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\LoginRequiredException){ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); // No permissions to edit artwork. Template::ExitWithCode(Enums\HttpCode::Forbidden); // No permissions to edit artwork.
} }
?> ?>

View file

@ -58,10 +58,10 @@ try{
} }
} }
catch(Exceptions\ArtworkNotFoundException){ catch(Exceptions\ArtworkNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); Template::ExitWithCode(Enums\HttpCode::Forbidden);
} }
?><?= Template::Header(['title' => $artwork->Name, 'css' => ['/css/artwork.css']]) ?> ?><?= Template::Header(['title' => $artwork->Name, 'css' => ['/css/artwork.css']]) ?>

View file

@ -124,7 +124,7 @@ try{
} }
} }
catch(Exceptions\ArtworkNotFoundException){ catch(Exceptions\ArtworkNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\PageOutOfBoundsException){ catch(Exceptions\PageOutOfBoundsException){
$url = '/artworks?page=' . $pages; $url = '/artworks?page=' . $pages;

View file

@ -41,7 +41,7 @@ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); // No permissions to submit artwork. Template::ExitWithCode(Enums\HttpCode::Forbidden); // No permissions to submit artwork.
} }
?> ?>

View file

@ -130,10 +130,10 @@ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); Template::ExitWithCode(Enums\HttpCode::Forbidden);
} }
catch(Exceptions\ArtworkNotFoundException){ catch(Exceptions\ArtworkNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\InvalidArtworkException | Exceptions\InvalidArtworkTagException | Exceptions\InvalidArtistException | Exceptions\InvalidFileUploadException $ex){ catch(Exceptions\InvalidArtworkException | Exceptions\InvalidArtworkTagException | Exceptions\InvalidArtistException | Exceptions\InvalidFileUploadException $ex){
// If we were passed a more generic file upload exception from `HttpInput`, swap it for a more specific exception to show to the user. // If we were passed a more generic file upload exception from `HttpInput`, swap it for a more specific exception to show to the user.

View file

@ -20,7 +20,7 @@ try{
$authorUrl = $ebooks[0]->AuthorsUrl; $authorUrl = $ebooks[0]->AuthorsUrl;
} }
catch(Exceptions\AuthorNotFoundException){ catch(Exceptions\AuthorNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => 'Ebooks by ' . $author, 'feedUrl' => str_replace('/ebooks/', '/authors/', $authorUrl), 'feedTitle' => 'Standard Ebooks - Ebooks by ' . $author, 'highlight' => 'ebooks', 'description' => 'All of the Standard Ebooks ebooks by ' . $author, 'canonicalUrl' => SITE_URL . $authorUrl]) ?> ?><?= Template::Header(['title' => 'Ebooks by ' . $author, 'feedUrl' => str_replace('/ebooks/', '/authors/', $authorUrl), 'feedTitle' => 'Standard Ebooks - Ebooks by ' . $author, 'highlight' => 'ebooks', 'description' => 'All of the Standard Ebooks ebooks by ' . $author, 'canonicalUrl' => SITE_URL . $authorUrl]) ?>
<main class="ebooks"> <main class="ebooks">

View file

@ -6,7 +6,7 @@ $canDownload = false;
$class = HttpInput::Str(GET, 'class'); $class = HttpInput::Str(GET, 'class');
if($class === null || ($class != 'authors' && $class != 'collections' && $class != 'subjects' && $class != 'months')){ if($class === null || ($class != 'authors' && $class != 'collections' && $class != 'subjects' && $class != 'months')){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
if(Session::$User?->Benefits->CanBulkDownload){ if(Session::$User?->Benefits->CanBulkDownload){

View file

@ -49,7 +49,7 @@ catch(Exceptions\InvalidPermissionsException){
http_response_code(Enums\HttpCode::Forbidden->value); http_response_code(Enums\HttpCode::Forbidden->value);
} }
catch(Exceptions\InvalidFileException){ catch(Exceptions\InvalidFileException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => 'Downloading Ebook Collections', 'highlight' => '', 'description' => 'Download zip files containing all of the Standard Ebooks released in a given month.']) ?> ?><?= Template::Header(['title' => 'Downloading Ebook Collections', 'highlight' => '', 'description' => 'Download zip files containing all of the Standard Ebooks released in a given month.']) ?>

View file

@ -67,10 +67,10 @@ try{
} }
} }
catch(Exceptions\AuthorNotFoundException){ catch(Exceptions\AuthorNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\CollectionNotFoundException){ catch(Exceptions\CollectionNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => 'Download ', 'highlight' => '', 'description' => 'Download zip files containing all of the Standard Ebooks released in a given month.']) ?> ?><?= Template::Header(['title' => 'Download ', 'highlight' => '', 'description' => 'Download zip files containing all of the Standard Ebooks released in a given month.']) ?>

View file

@ -14,7 +14,7 @@ try{
$feedTitle = 'Standard Ebooks - Ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . $collectionType; $feedTitle = 'Standard Ebooks - Ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . $collectionType;
} }
catch(Exceptions\CollectionNotFoundException){ catch(Exceptions\CollectionNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => $pageTitle, 'feedUrl' => $feedUrl, 'feedTitle' => $feedTitle, 'highlight' => 'ebooks', 'description' => $pageDescription]) ?> ?><?= Template::Header(['title' => $pageTitle, 'feedUrl' => $feedUrl, 'feedTitle' => $feedTitle, 'highlight' => 'ebooks', 'description' => $pageDescription]) ?>
<main class="ebooks"> <main class="ebooks">

View file

@ -32,13 +32,13 @@ try{
} }
} }
catch(Exceptions\EbookNotFoundException){ catch(Exceptions\EbookNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\LoginRequiredException){ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); Template::ExitWithCode(Enums\HttpCode::Forbidden);
} }
?> ?>
<?= Template::Header( <?= Template::Header(

View file

@ -21,7 +21,7 @@ try{
} }
} }
catch(Exceptions\EbookNotFoundException){ catch(Exceptions\EbookNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header( ?><?= Template::Header(
[ [

View file

@ -55,7 +55,7 @@ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); // No permissions to create an ebook placeholder. Template::ExitWithCode(Enums\HttpCode::Forbidden); // No permissions to create an ebook placeholder.
} }
?> ?>
<?= Template::Header( <?= Template::Header(

View file

@ -110,7 +110,7 @@ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException | Exceptions\InvalidHttpMethodException | Exceptions\HttpMethodNotAllowedException){ catch(Exceptions\InvalidPermissionsException | Exceptions\InvalidHttpMethodException | Exceptions\HttpMethodNotAllowedException){
Template::Emit403(); Template::ExitWithCode(Enums\HttpCode::Forbidden);
} }
catch(Exceptions\AppException $ex){ catch(Exceptions\AppException $ex){
$_SESSION['ebook'] = $ebook; $_SESSION['ebook'] = $ebook;

View file

@ -59,7 +59,7 @@ try{
setcookie('download-count', (string)$downloadCount, ['expires' => intval((new DateTimeImmutable('+2 week'))->format(Enums\DateTimeFormat::UnixTimestamp->value)), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); setcookie('download-count', (string)$downloadCount, ['expires' => intval((new DateTimeImmutable('+2 week'))->format(Enums\DateTimeFormat::UnixTimestamp->value)), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']);
} }
catch(Exceptions\InvalidFileException | Exceptions\EbookNotFoundException){ catch(Exceptions\InvalidFileException | Exceptions\EbookNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => 'Your Download Has Started!', 'downloadUrl' => $downloadUrl]) ?> ?><?= Template::Header(['title' => 'Your Download Has Started!', 'downloadUrl' => $downloadUrl]) ?>
<main class="donate"> <main class="donate">

View file

@ -21,15 +21,15 @@ try{
} }
// Editing published `Ebooks` is not supported. // Editing published `Ebooks` is not supported.
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\EbookNotFoundException){ catch(Exceptions\EbookNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\LoginRequiredException){ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); Template::ExitWithCode(Enums\HttpCode::Forbidden);
} }

View file

@ -75,7 +75,7 @@ catch(Exceptions\EbookNotFoundException){
exit(); exit();
} }
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'ogType' => 'book', 'coverUrl' => $ebook->DistCoverUrl, 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description, 'canonicalUrl' => SITE_URL . $ebook->Url]) ?> ?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'ogType' => 'book', 'coverUrl' => $ebook->DistCoverUrl, 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description, 'canonicalUrl' => SITE_URL . $ebook->Url]) ?>
<main> <main>

View file

@ -21,15 +21,15 @@ try{
} }
// POSTing published `Ebooks` is not supported. // POSTing published `Ebooks` is not supported.
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\EbookNotFoundException){ catch(Exceptions\EbookNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\LoginRequiredException){ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); Template::ExitWithCode(Enums\HttpCode::Forbidden);
} }

View file

@ -39,7 +39,7 @@ try{
} }
} }
catch(Exceptions\EbookNotFoundException){ catch(Exceptions\EbookNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description, 'canonicalUrl' => SITE_URL . $ebook->Url]) ?> ?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description, 'canonicalUrl' => SITE_URL . $ebook->Url]) ?>
<main> <main>

View file

@ -6,11 +6,11 @@ $collectionType = Enums\FeedCollectionType::tryFrom(HttpInput::Str(GET, 'class')
$type = Enums\FeedType::tryFrom(HttpInput::Str(GET, 'type') ?? ''); $type = Enums\FeedType::tryFrom(HttpInput::Str(GET, 'type') ?? '');
if($collectionType === null){ if($collectionType === null){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
if($type === null || ($type != Enums\FeedType::Rss && $type != Enums\FeedType::Atom)){ if($type === null || ($type != Enums\FeedType::Rss && $type != Enums\FeedType::Atom)){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
$feeds = []; $feeds = [];
@ -26,7 +26,7 @@ catch(Safe\Exceptions\ApcuException){
$feeds = Feed::RebuildFeedsCache($type, $collectionType); $feeds = Feed::RebuildFeedsCache($type, $collectionType);
if($feeds === null){ if($feeds === null){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
} }
?><?= Template::Header(['title' => $type->GetDisplayName() . ' Ebook Feeds by ' . $ucTitle, 'description' => 'A list of available ' . $type->GetDisplayName() . ' feeds of Standard Ebooks ebooks by ' . $lcTitle . '.']) ?> ?><?= Template::Header(['title' => $type->GetDisplayName() . ' Ebook Feeds by ' . $ucTitle, 'description' => 'A list of available ' . $type->GetDisplayName() . ' feeds of Standard Ebooks ebooks by ' . $lcTitle . '.']) ?>

View file

@ -104,7 +104,7 @@ catch(Exceptions\InvalidPermissionsException){
http_response_code(Enums\HttpCode::Forbidden->value); http_response_code(Enums\HttpCode::Forbidden->value);
} }
catch(Exceptions\InvalidFileException){ catch(Exceptions\InvalidFileException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
// Print the login info page. // Print the login info page.

View file

@ -53,7 +53,7 @@ try{
$feedUrl = '/' . $collectionType->value . '/' . $target; $feedUrl = '/' . $collectionType->value . '/' . $target;
} }
catch(Exceptions\CollectionNotFoundException){ catch(Exceptions\CollectionNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => $title, 'feedTitle' => $feedTitle, 'feedUrl' => $feedUrl, 'description' => $description]) ?> ?><?= Template::Header(['title' => $title, 'feedTitle' => $feedTitle, 'feedUrl' => $feedUrl, 'description' => $description]) ?>
<main> <main>

View file

@ -15,7 +15,7 @@ try{
$url = preg_replace('|/$|ius', '', $url); $url = preg_replace('|/$|ius', '', $url);
} }
catch(\Exception){ catch(\Exception){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
if($url != ''){ if($url != ''){

View file

@ -15,5 +15,5 @@ try{
header('Location: ' . $subscription->Url); header('Location: ' . $subscription->Url);
} }
catch(Exceptions\NewsletterSubscriptionNotFoundException){ catch(Exceptions\NewsletterSubscriptionNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }

View file

@ -14,7 +14,7 @@ try{
} }
catch(Exceptions\NewsletterSubscriptionNotFoundException){ catch(Exceptions\NewsletterSubscriptionNotFoundException){
if($requestType == Enums\HttpRequestType::Web){ if($requestType == Enums\HttpRequestType::Web){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
else{ else{
http_response_code(Enums\HttpCode::NotFound->value); http_response_code(Enums\HttpCode::NotFound->value);

View file

@ -38,7 +38,7 @@ try{
} }
} }
catch(Exceptions\AppException){ catch(Exceptions\AppException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => 'Your Subscription to the Standard Ebooks Newsletter', 'highlight' => 'newsletter', 'description' => 'Your subscription to the Standard Ebooks newsletter.']) ?> ?><?= Template::Header(['title' => 'Your Subscription to the Standard Ebooks Newsletter', 'highlight' => 'newsletter', 'description' => 'Your subscription to the Standard Ebooks newsletter.']) ?>

View file

@ -23,7 +23,7 @@ try{
} }
} }
catch(Exceptions\AppException){ catch(Exceptions\AppException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => $poll->Name, 'highlight' => '', 'description' => $poll->Description]) ?> ?><?= Template::Header(['title' => $poll->Name, 'highlight' => '', 'description' => $poll->Description]) ?>

View file

@ -16,7 +16,7 @@ try{
} }
} }
catch(Exceptions\AppException){ catch(Exceptions\AppException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => 'Your Vote Has Been Recorded!', 'highlight' => '', 'description' => 'Thank you for voting in a Standard Ebooks poll!']) ?> ?><?= Template::Header(['title' => 'Your Vote Has Been Recorded!', 'highlight' => '', 'description' => 'Thank you for voting in a Standard Ebooks poll!']) ?>

View file

@ -5,7 +5,7 @@ try{
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname')); $poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname'));
} }
catch(Exceptions\AppException){ catch(Exceptions\AppException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
?><?= Template::Header(['title' => 'Results for the ' . $poll->Name . ' Poll', 'highlight' => '', 'description' => 'The voting results for the ' . $poll->Name . ' poll.']) ?> ?><?= Template::Header(['title' => 'Results for the ' . $poll->Name . ' Poll', 'highlight' => '', 'description' => 'The voting results for the ' . $poll->Name . ' poll.']) ?>

View file

@ -38,7 +38,7 @@ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\PollNotFoundException){ catch(Exceptions\PollNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\PollVoteExistsException $ex){ catch(Exceptions\PollVoteExistsException $ex){
$redirect = $poll->Url; $redirect = $poll->Url;

View file

@ -33,7 +33,7 @@ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); Template::ExitWithCode(Enums\HttpCode::Forbidden);
} }
?><?= Template::Header([ ?><?= Template::Header([
'title' => 'Projects', 'title' => 'Projects',

View file

@ -44,13 +44,13 @@ try{
} }
} }
catch(Exceptions\EbookNotFoundException){ catch(Exceptions\EbookNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\LoginRequiredException){ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); Template::ExitWithCode(Enums\HttpCode::Forbidden);
} }
?><?= Template::Header([ ?><?= Template::Header([
'title' => 'New Project', 'title' => 'New Project',

View file

@ -28,13 +28,13 @@ try{
} }
} }
catch(Exceptions\EbookNotFoundException){ catch(Exceptions\EbookNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\LoginRequiredException){ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); Template::ExitWithCode(Enums\HttpCode::Forbidden);
} }
catch(Exceptions\InvalidProjectException | Exceptions\ProjectExistsException | Exceptions\EbookIsNotAPlaceholderException $ex){ catch(Exceptions\InvalidProjectException | Exceptions\ProjectExistsException | Exceptions\EbookIsNotAPlaceholderException $ex){
$_SESSION['project'] = $project; $_SESSION['project'] = $project;

View file

@ -28,13 +28,13 @@ try{
} }
} }
catch(Exceptions\UserNotFoundException){ catch(Exceptions\UserNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\LoginRequiredException){ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); // No permissions to edit artwork. Template::ExitWithCode(Enums\HttpCode::Forbidden); // No permissions to edit artwork.
} }
?> ?>
<?= Template::Header( <?= Template::Header(

View file

@ -22,13 +22,13 @@ try{
} }
} }
catch(Exceptions\UserNotFoundException){ catch(Exceptions\UserNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\LoginRequiredException){ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); Template::ExitWithCode(Enums\HttpCode::Forbidden);
} }
?><?= Template::Header( ?><?= Template::Header(
[ [

View file

@ -58,10 +58,10 @@ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); Template::ExitWithCode(Enums\HttpCode::Forbidden);
} }
catch(Exceptions\UserNotFoundException){ catch(Exceptions\UserNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\InvalidUserException | Exceptions\UserExistsException $ex){ catch(Exceptions\InvalidUserException | Exceptions\UserExistsException $ex){
if($generateNewUuid){ if($generateNewUuid){

View file

@ -20,13 +20,13 @@ try{
$reviewingProjects = Project::GetAllByReviewerUserId($user->UserId); $reviewingProjects = Project::GetAllByReviewerUserId($user->UserId);
} }
catch(Exceptions\UserNotFoundException){ catch(Exceptions\UserNotFoundException){
Template::Emit404(); Template::ExitWithCode(Enums\HttpCode::NotFound);
} }
catch(Exceptions\LoginRequiredException){ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); Template::ExitWithCode(Enums\HttpCode::Forbidden);
} }
?><?= Template::Header( ?><?= Template::Header(
[ [