diff --git a/view_poll.php b/view_poll.php
index 2a3d43a..bf62e74 100644
--- a/view_poll.php
+++ b/view_poll.php
@@ -5,6 +5,8 @@ require_once __DIR__ .'/bootstrap.php';
use APnutI\Exceptions\NotFoundException;
use APnutI\Exceptions\HttpPnutForbiddenException;
use APnutI\Exceptions\NotSupportedPollException;
+use APnutI\Exceptions\NotAuthorizedException;
+use APnutI\Exceptions\PollAccessRestrictedException;
use APnutI\Entities\Poll;
if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) {
@@ -12,19 +14,55 @@ if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) {
}
$poll_id = (int)$_GET['id'];
$poll = null;
+
+if ($api->isAuthenticated()) {
+ $user = $api->getAuthorizedUser();
+ echo 'Welcome ' . ($user->name ?? $user->username) . '
';
+}
+
try {
- $poll = $api->getPoll($poll_id);
+ $poll_token = array_key_exists('polltoken', $_GET) ? $_GET['polltoken'] : null;
+ $poll = $api->getPoll($poll_id, $poll_token);
} catch (NotFoundException $nfe) {
die('Poll not found');
-} catch (HttpPnutForbiddenException $fe) {
- die('Poll token required!');
} catch (NotSupportedPollException $nspe) {
die('Sorry, this poll has a not yet supported type: ' . $nspe->getMessage());
+} catch (PollAccessRestrictedException $are) {
+ $message = array_key_exists('polltoken', $_GET)
+ ? 'Sorry, your poll token is invalid! Please enter a valid token: '
+ : ('Sorry, this poll is private! If you have found this poll on a post, '
+ . 'please enter a link to the post, the post ID or the access token for the poll: ');
+ die(
+ $message
+ . '