Beispiel #1
0
 public static function generate($_asJson = true)
 {
     $result = array();
     $publicKey = sha1(mt_rand_str(40));
     $privateKey = sha1(mt_rand_str(40));
     #if(CWM_API::IsTokenValid($tokenValue)) {
     if (isUserLoggedIn()) {
         $result = array('public' => $publicKey, 'private' => $privateKey);
     }
     if ($_asJson) {
         $result = CWM_API::getAsJson($result);
     }
     return $result;
 }
Beispiel #2
0
// Get a file by file ID
$f3->route('GET ' . $apiBaseUrl . '/file/@fileId/@tokenValue', function ($f3) {
    require_once $GLOBALS['dirRoot'] . '/api/File.class.php';
    $fileId = $f3->get('PARAMS.fileId');
    $tokenValue = $f3->get('PARAMS.tokenValue');
    $file = CWM_File::get($fileId, $tokenValue);
    echo CWM_API::getAsJson($file);
});
// Get a file by project ID and file name
$f3->route('GET ' . $apiBaseUrl . '/file/@projectId/@fileName/@tokenValue', function ($f3) {
    require_once $GLOBALS['dirRoot'] . '/api/File.class.php';
    $projectId = $f3->get('PARAMS.projectId');
    $fileName = $f3->get('PARAMS.fileName');
    $tokenValue = $f3->get('PARAMS.tokenValue');
    $file = CWM_File::getByProjectIdFileName($projectId, $fileName, $tokenValue);
    echo CWM_API::getAsJson($file);
});
// Create a file
$f3->route('POST ' . $apiBaseUrl . '/file/create/@tokenValue', function ($f3) {
    require_once $GLOBALS['dirRoot'] . '/api/File.class.php';
    $tokenValue = $f3->get('PARAMS.tokenValue');
    if (CWM_API::isTokenValid($tokenValue)) {
        $jsonData = json_decode($f3->get('BODY'));
        $_projectId = $jsonData->{'ProjectId'};
        $_fileName = $jsonData->{'Name'};
        $_fileData = $jsonData->{'Data'};
        $_userId = CWM_API::getUserId($tokenValue);
        $_solutionName = $jsonData->{'SolutionName'};
        $_projectName = $jsonData->{'ProjectName'};
        $_file = new CWM_File(-1, $_projectId, $_fileName, $_fileData, $_userId, $_solutionName, $_projectName, null);
        $_file->create();