diff --git a/appinfo/routes.php b/appinfo/routes.php index cd7665b2f0517429302fb300502dbe10dfdd5dfa..5b60986f05fc8d71aba601e32531959f610ab9fa 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -25,6 +25,8 @@ declare(strict_types=1); */ return [ 'routes' => [ + //Maybe invitiation + ['name' => 'invitation_maybe#tentative', 'url' => '/invitation/tentative/{token}', 'verb' => 'GET'], // User views ['name' => 'view#index', 'url' => '/', 'verb' => 'GET'], ['name' => 'view#index', 'url' => '/new', 'verb' => 'GET', 'postfix' => 'direct.new'], diff --git a/lib/Controller/InvitationMaybeController.php b/lib/Controller/InvitationMaybeController.php new file mode 100755 index 0000000000000000000000000000000000000000..c7fdad4997ff09841b44662f96b8e3afc0e6ce6f --- /dev/null +++ b/lib/Controller/InvitationMaybeController.php @@ -0,0 +1,155 @@ +db = $db; + $this->timeFactory = $timeFactory; + $this->responseServer = $responseServer; + // Don't run `$server->exec()`, because we just need access to the + // fully initialized schedule plugin, but we don't want Sabre/DAV + // to actually handle and reply to the request + } + /** + * @PublicPage + * @NoCSRFRequired + * + * @param string $token + * @return TemplateResponse + */ + public function tentative(string $token):TemplateResponse { + $row = $this->getTokenInformation($token); + if (!$row) { + return new TemplateResponse($this->appName, 'schedule-response-error', [], 'guest'); + } + $iTipMessage = $this->buildITipResponse($row, 'TENTATIVE'); + $this->responseServer->handleITipMessage($iTipMessage); + + if ($iTipMessage->getScheduleStatus() === '1.2') { + return new TemplateResponse($this->appName, 'schedule-response-success', [], 'guest'); + } + + return new TemplateResponse($this->appName, 'schedule-response-error', [ + 'organizer' => $row['organizer'], + ], 'guest'); + } + + /** + * @param array $row + * @param string $partStat participation status of attendee - SEE RFC 5545 + * @param int|null $guests + * @param string|null $comment + * @return Message + */ + private function buildITipResponse(array $row, string $partStat, int $guests = null, + string $comment = null):Message { + $iTipMessage = new Message(); + $iTipMessage->uid = $row['uid']; + $iTipMessage->component = 'VEVENT'; + $iTipMessage->method = 'REPLY'; + $iTipMessage->sequence = $row['sequence']; + $iTipMessage->sender = $row['attendee']; + + if ($this->responseServer->isExternalAttendee($row['attendee'])) { + $iTipMessage->recipient = $row['organizer']; + } else { + $iTipMessage->recipient = $row['attendee']; + } + + $message = <<{'VEVENT'}; + /** @var \Sabre\VObject\Property\ICalendar\CalAddress $attendee */ + $attendee = $vEvent->{'ATTENDEE'}; + + $vEvent->DTSTAMP = date('Ymd\\THis\\Z', $this->timeFactory->getTime()); + + if ($comment) { + $attendee->add('X-RESPONSE-COMMENT', $comment); + $vEvent->add('COMMENT', $comment); + } + if ($guests) { + $attendee->add('X-NUM-GUESTS', $guests); + } + + $iTipMessage->message = $vObject; + + return $iTipMessage; + } + + + /** + * @param string $token + * @return array|null + */ + private function getTokenInformation(string $token) { + $query = $this->db->getQueryBuilder(); + $query->select('*') + ->from('calendar_invitations') + ->where($query->expr()->eq('token', $query->createNamedParameter($token))); + $stmt = $query->execute(); + $row = $stmt->fetch(\PDO::FETCH_ASSOC); + + if (!$row) { + return null; + } + + $currentTime = $this->timeFactory->getTime(); + if (((int) $row['expiration']) < $currentTime) { + return null; + } + + return $row; + } + +} \ No newline at end of file diff --git a/templates/schedule-response-error.php b/templates/schedule-response-error.php new file mode 100755 index 0000000000000000000000000000000000000000..010ea2ed6cbca605be3de9b0851ea354e2f5d928 --- /dev/null +++ b/templates/schedule-response-error.php @@ -0,0 +1,7 @@ +
+

t('There was an error updating your attendance status.'));?>

+

t('Please contact the organizer directly.'));?>

+ +

+ +
diff --git a/templates/schedule-response-options.php b/templates/schedule-response-options.php new file mode 100755 index 0000000000000000000000000000000000000000..f5ebb46cb2614448a94833735f488af22acec852 --- /dev/null +++ b/templates/schedule-response-options.php @@ -0,0 +1,34 @@ + + +
+
+
+

t('Are you accepting the invitation?')); ?>

+
+ + + + + + + + +
+
+
+ + +
+
+ +
+
+
diff --git a/templates/schedule-response-success.php b/templates/schedule-response-success.php new file mode 100755 index 0000000000000000000000000000000000000000..f60cb1e0fa97ad051c8157df80bc8f4e57cfba79 --- /dev/null +++ b/templates/schedule-response-success.php @@ -0,0 +1,4 @@ +
+ +

t('Your attendance was updated successfully.'));?>

+