Beispiel #1
0
 public function __construct($userDir, $userId, Url $baseUrl, Calendar $calendar, SettingsStore $settings)
 {
     $this->settings = $settings;
     $this->calendar = $calendar;
     $this->userId = $userId;
     $this->handler = new ApplicationService(new Application(new UidGenerator(), $settings->read(), $calendar, $baseUrl, new \DateTimeImmutable()), new PersistentEventStore($userDir . '/events.json'));
 }
Beispiel #2
0
 /**
  * @param mixed[] $parameters Values indexed by name
  * @return mixed the result of the execution
  * @throws \Exception if Action cannot be executed
  */
 public function execute(array $parameters)
 {
     $settings = $this->settings->read();
     $settings->calendarId = $parameters['calendar'];
     $this->settings->write($settings);
     if (!$settings->calendarId) {
         return 'Calendar synchronization deactivated';
     }
     return 'Calendar set to [' . $settings->calendarId . ']';
 }
Beispiel #3
0
}
if (isset($_GET['code'])) {
    $client->authenticate($_GET['code']);
    $_SESSION['token'] = $client->getAccessToken();
    header('Location: ' . ($_SESSION['targetUrl'] ?: '/'));
    exit;
}
if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
}
$redirectToAuthUrl = function () use($client) {
    $_SESSION['targetUrl'] = (string) Url::fromString($_SERVER['REQUEST_URI'])->withParameters(Collection::toCollections($_REQUEST));
    $authUrl = $client->createAuthUrl();
    header('Location: ' . $authUrl);
    exit;
};
if (!$client->getAccessToken()) {
    $redirectToAuthUrl();
}
$cal = new Google_Service_Calendar($client);
$info = new Google_Service_Oauth2($client);
try {
    $userId = $info->userinfo->get()->email;
    $userDir = __DIR__ . '/user/' . $userId;
    $settingsStore = new SettingsStore($userDir);
    $calendar = new GoogleCalendar($cal, $settingsStore->read()->calendarId);
    (new Bootstrapper($userDir, $userId, Url::fromString(dirname($baseUrl)), $calendar, $settingsStore))->runWebApp();
} catch (Google_Auth_Exception $e) {
    unset($_SESSION['token']);
    $redirectToAuthUrl();
}