web/www/newsletter/subscriptions/delete.php
2022-07-04 12:09:49 -05:00

42 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?
require_once('Core.php');
use function Safe\preg_match;
$requestType = HttpInput::RequestType();
try{
// We may use GET if we're called from an unsubscribe link in an email
if(!in_array(HttpInput::RequestMethod(), [HTTP_DELETE, HTTP_GET])){
throw new Exceptions\InvalidRequestException();
}
$subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid') ?? '');
$subscription->Delete();
if($requestType == REST){
exit();
}
}
catch(Exceptions\InvalidRequestException $ex){
http_response_code(405);
exit();
}
catch(Exceptions\InvalidNewsletterSubscriptionException $ex){
if($requestType == WEB){
Template::Emit404();
}
else{
http_response_code(404);
exit();
}
}
?><?= Template::Header(['title' => 'Youve unsubscribed from the Standard Ebooks newsletter', 'highlight' => 'newsletter', 'description' => 'Youve unsubscribed from the Standard Ebooks newsletter.']) ?>
<main>
<article>
<h1>Youve been unsubscribed</h1>
<p>Youll no longer receive Standard Ebooks email newsletters. Sorry to see you go!</p>
</article>
</main>
<?= Template::Footer() ?>