Пример #1
0
 /**
  * Adds a project to the solution
  * @param [int] $solutionId
  * @param [int] $projectId
  * @param [string] $tokenValue
  * @return [int] Returns -1 if invalid token, 1 if valid token and project was added to the solution, 0 if valid token, but project is already connected the solution
  */
 public static function addProject($solutionId, $projectId, $tokenValue)
 {
     $result = -1;
     if (CWM_API::IsTokenValid($tokenValue)) {
         $row = DB::queryFirstRow("SELECT * FROM CWM_SolutionProject WHERE SolutionId=%? AND ProjectId=%?", $solutionId, $projectId);
         $result = is_null($row) == true ? 1 : 0;
         if ($result) {
             $result = DB::insert('CWM_SolutionProject', array('SolutionId' => $solutionId, 'ProjectId' => $projectId));
         }
     }
     return $result;
 }
Пример #2
0
 public static function getFromToken($tokenValue)
 {
     $user = null;
     if (CWM_API::IsTokenValid($tokenValue)) {
         $row = DB::queryFirstRow("SELECT * FROM CWM_User as u JOIN CWM_ApiKeySession as aks ON u.Id = aks.UserId WHERE aks.TokenValue=%?", $tokenValue);
         if (!is_null($row)) {
             $status = $row['Status'] == '1' ? true : false;
             $isFirstTime = $row['IsFirstTime'] == '1' ? true : false;
             $user = new CWM_User($row['UserId'], $row['Email'], "", "", $status, $isFirstTime);
         }
     }
     return $user;
 }
Пример #3
0
<?php

require_once $GLOBALS['dirLibs'] . '/external/meekrodb.2.2.class.php';
require_once $GLOBALS['dirCore'] . '/dbConfig.inc.php';
require_once $GLOBALS['dirRoot'] . '/api/ApiAuth.class.php';
$results = array();
$tokenValue = $f3->get('PARAMS.tokenValue');
if (CWM_API::IsTokenValid($tokenValue)) {
    $userId = DB::queryOneField("Id", "SELECT * FROM CWM_ApiKeySession aks JOIN CWM_User as u ON aks.UserId = u.Id WHERE TokenValue=%?", $tokenValue);
    $results = DB::query("SELECT * FROM CWM_Solution WHERE UserId=%?", $userId);
}
echo json_encode($results);
Пример #4
0
 /**
  * Updates a file
  * @param  [int] $fileId File ID
  * @param  [int] $name File name
  * @param  [int] $data File data
  * @param  [string] $tokenValue
  * @return [int] -1 if invalid token, 1 if valid token and file was updated, 0, if valid token, but file content was same (no update performed)
  */
 public static function update($id, $name, $data, $tokenValue)
 {
     $result = -1;
     if (CWM_API::IsTokenValid($tokenValue)) {
         DB::update('CWM_File', array('Name' => $name, 'Data' => $data), "Id=%?", $id);
         $result = DB::affectedRows();
     }
     return $result;
 }
Пример #5
0
    $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();
        echo $_file->ID;
        //json_encode(array('ID' => $_file->ID));
    } else {
        echo -1;
    }
});
// Update a file
$f3->route('PUT ' . $apiBaseUrl . '/file/update/@tokenValue', function ($f3) {
    require_once $GLOBALS['dirRoot'] . '/api/File.class.php';
    $jsonData = json_decode($f3->get('BODY'));
    $tokenValue = $f3->get('PARAMS.tokenValue');
Пример #6
0
 private static function resetToken($datetimeValid, $tokenValue)
 {
     $dateInPast = new DateTime(CWM_API::getDateTime(time()));
     $dateInPast->sub(new DateInterval($datetimeValid));
     return DB::update('CWM_ApiKeySession', array('LastAccess' => $dateInPast, 'TokenValue' => ''), "TokenValue=%?", $tokenValue);
 }