Exemplo n.º 1
0
    list($token, $token_secret) = get_oauth_access_token($consumer_data, $request_token, $request_token_secret);
    if (!$token || !$token_secret) {
        throw new Exception("Getting OAuth access token from Get Satisfaction failed.");
    }
    $result = mysql_query("update sessions set token = '" . mysql_real_escape_string($token) . "', token_secret = '" . mysql_real_escape_string($token_secret) . "' where token = '" . mysql_real_escape_string($request_token) . "'");
    if (!$result) {
        throw new Exception("Failed to store auth tokens on oauth response");
    }
    $sprink = new Sprinkles();
    $sprink->open_session($token);
    if (!$sprink->site_configured() && request_param('first_login')) {
        $user = $sprink->current_user();
        if (!$user) {
            throw new Exception("Internal error: No current user just after opening session.");
        }
        $sprink->set_admin_users(array($user['canonical_name']));
        $result = $sprink->set_site_settings(array('configured' => 'Y'));
        if (!$result) {
            die(mysql_error());
        }
    }
    $return = request_param('return');
    if (!$return) {
        $return = 'helpstart.php';
    }
    redirect($return);
    exit(0);
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}
    $company_sfnid = request_param('company_sfnid');
    $oauth_consumer_key = request_param('oauth_consumer_key');
    $oauth_consumer_secret = request_param('oauth_consumer_secret');
    $sprinkles_root_url = request_param('sprinkles_root_url');
    if (!$oauth_consumer_key || !$oauth_consumer_secret) {
        redirect('admin-findsite.php?msg=missing_oauth' . '&company_sfnid=' . $company_sfnid . '&oauth_consumer_key=' . $oauth_consumer_key . '&oauth_consumer_secret=' . $oauth_consumer_secret . '&sprinkles_root_url=' . $sprinkles_root_url);
        exit;
    }
    if (!$sprinkles_root_url) {
        redirect('admin-findsite.php?msg=missing_sprinkles_root_url' . '&company_sfnid=' . $company_sfnid . '&oauth_consumer_key=' . $oauth_consumer_key . '&oauth_consumer_secret=' . $oauth_consumer_secret . '&sprinkles_root_url=' . $sprinkles_root_url);
        exit;
    }
    if (!$company_sfnid) {
        redirect('admin-findsite.php?msg=missing_company_sfnid' . '&company_sfnid=' . $company_sfnid . '&oauth_consumer_key=' . $oauth_consumer_key . '&oauth_consumer_secret=' . $oauth_consumer_secret . '&sprinkles_root_url=' . $sprinkles_root_url);
        exit;
    }
    $sprinkles_root_url = preg_replace('|[^/]*.php$|', '', $sprinkles_root_url);
    # Note: the naive regex you'd usee below doesn't work; pcre is not in fact
    # Perl-compatible in this case
    $sprinkles_root_url = preg_replace('|([^/])/*$|', '\\1/', $sprinkles_root_url);
    $result = $sprink->set_site_settings(array('company_id' => $company_sfnid, 'oauth_consumer_key' => $oauth_consumer_key, 'oauth_consumer_secret' => $oauth_consumer_secret, 'sprinkles_root_url' => $sprinkles_root_url));
    if (!$result) {
        die(mysql_error());
    }
    message($sprink->site_configured());
    redirect($sprink->authorize_url('admin.php?hooked=true', true));
    exit(0);
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}