Added canVote() to poll

This commit is contained in:
aymm 2021-03-27 10:06:48 +00:00
parent e639234a95
commit d3f85ad779
2 changed files with 8 additions and 1 deletions

View File

@ -328,7 +328,7 @@ class APnutI
} }
//TODO: Ping server and validate token //TODO: Ping server and validate token
public function isAuthenticated(bool $allow_server_token = false): bool public function isAuthenticated(bool $allow_server_token = false, bool $skip_verify_token = false): bool
{ {
$is_authenticated = ($allow_server_token && !empty($this->server_token)) $is_authenticated = ($allow_server_token && !empty($this->server_token))
|| isset($this->access_token); || isset($this->access_token);

View File

@ -122,6 +122,13 @@ class Poll
return $type === Poll::$notice_type || in_array($type, Poll::$poll_types); return $type === Poll::$notice_type || in_array($type, Poll::$poll_types);
} }
public function canVote()
{
$is_authenticated = $this->api->isAuthenticated(false, true);
$is_closed = $this->closed_at >= new \DateTime();
return $is_authenticated && !$is_closed;
}
public function __toString(): string public function __toString(): string
{ {
if (!empty($this->user)) { if (!empty($this->user)) {