Ejemplo n.º 1
0
    }
    if (!isset($_SESSION['account_href'])) {
        getAccounts($_SESSION['token']);
    }
    if (!isset($_SESSION['project_href'])) {
        getProjects($_SESSION['account_href'], $_SESSION['token']);
    }
    getTodos($_SESSION['project'], $_SESSION['token']);
} else {
    switch ($_GET['action']) {
        case 'redirect':
            if (!isset($_GET['code'])) {
                throw new InvalidArgumentException("verification code missing");
            }
            $verification_code = $_GET['code'];
            $tokens = $oauth->exchangeVerificationCode($verification_code);
            $_SESSION['token'] = $tokens['access_token'];
            setcookie('token', $tokens['access_token']);
            file_put_contents('tokens', serialize($tokens) . "\n-----------------------\n", FILE_APPEND);
            getAccounts($tokens['access_token']);
            break;
        case 'choose_user':
            $_SESSION['account_href'] = $_POST['url_base'];
            setcookie('account_href', $_POST['url_base']);
            header('Location: index.php');
            break;
        case 'choose_project':
            $_SESSION['project_href'] = $_POST['project_url'];
            setcookie('project_href', $_POST['project_url']);
            $_SESSION['project'] = $_POST['project'];
            setcookie('project', $_POST['project']);