public static function authenticateWithToken($token)
 {
     global $wpdb;
     $response = array('error' => false);
     if (strlen($token) < 32) {
         $response['error'] = true;
         $response['errorType'] = 'UserException';
         $response['errorMessage'] = __('Invalid token', 'bim-bcf-management');
     } else {
         $userId = $wpdb->get_var($wpdb->prepare("SELECT user_id\n            FROM {$wpdb->usermeta}\n            WHERE meta_key LIKE '_bcf_viewer_token_%%' AND meta_value COLLATE utf8_bin LIKE %s", $token));
         if ($userId != '') {
             $timestamp = get_user_meta($userId, '_bcf_viewer_timestamp', true);
             if ($timestamp > time()) {
                 // Token is valid
                 $serverId = $wpdb->get_var($wpdb->prepare("SELECT meta_key\n                  FROM {$wpdb->usermeta}\n                  WHERE meta_key LIKE '_bcf_viewer_token_%%' AND meta_value COLLATE utf8_bin LIKE %s AND user_id = %d", $token, $userId));
                 $serverId = str_replace('_bcf_viewer_token_', '', $serverId);
                 $server = BIMsie::getServerById($serverId, $userId);
                 if ($server !== false) {
                     $tokenData = get_user_meta($userId, 'bimsie_token', true);
                     if (isset($tokenData) && $tokenData != '' && $tokenData['timestamp'] > time() - Bimsie::$tokenTimeout) {
                         // Token is still valid
                         $token = BIMsie::updateTokenTimestamp($userId);
                     } else {
                         $token = BIMsie::updateTokenTimestamp($userId, BIMSie::generateToken());
                     }
                     $response['result'] = array('bimserver_url' => $server['uri'], 'bimserver_username' => $server['username'], 'bimserver_password' => $server['password'], 'bcfserver_token' => $token);
                 } else {
                     $response['error'] = true;
                     $response['errorType'] = 'UserException';
                     $response['errorMessage'] = __('Invalid token', 'bim-bcf-management');
                 }
             } else {
                 $response['error'] = true;
                 $response['errorType'] = 'UserException';
                 $response['errorMessage'] = __('Expired token', 'bim-bcf-management');
             }
         } else {
             $response['error'] = true;
             $response['errorType'] = 'UserException';
             $response['errorMessage'] = __('Invalid token', 'bim-bcf-management');
         }
     }
     return $response;
 }
Пример #2
0
                 $invalid = true;
                 $errorType = 'InvalidRequest';
                 $errorMessage = __('Invalid parameters or not allowed to comment on this issue.', 'bim-bcf-management');
             }
         } else {
             $invalid = true;
             $errorType = 'InvalidRequest';
             $errorMessage = __('Unsupported interface or method, check supported methods by browsing to: ', 'bim-bcf-management') . plugins_url('api.php', __FILE__);
         }
     } else {
         $invalid = true;
         $errorType = 'UserException';
         $errorMessage = __('Invalid token', 'bim-bcf-management');
     }
 } elseif ($request['request']['method'] == 'getComments') {
     $userId = BIMsie::getUserIdByToken(isset($request['token']) ? $request['token'] : '');
     if ($userId !== false) {
         if (isset($request['request']['parameters']['bimsieUrl'])) {
             $result = BIMBCFManagement::getComments($request['request']['parameters']['bimsieUrl'], $userId);
             if ($result === false) {
                 $invalid = true;
                 $errorType = 'InvalidRequest';
                 $errorMessage = __('Invalid parameters or not allowed to comment on this issue.', 'bim-bcf-management');
             }
         } else {
             $invalid = true;
             $errorType = 'InvalidRequest';
             $errorMessage = __('Unsupported interface or method, check supported methods by browsing to: ', 'bim-bcf-management') . plugins_url('api.php', __FILE__);
         }
     } else {
         $invalid = true;
Пример #3
0
 public static function updateServer($uri, $username, $password, $remember, $userId = -1)
 {
     $servers = BIMsie::getServers(false, $userId);
     $found = false;
     foreach ($servers as $key => $server) {
         if ($server['uri'] == $uri) {
             if ($remember == 1) {
                 $servers[$key] = array('uri' => $uri, 'remember' => 1, 'username' => $username, 'password' => $password);
             } else {
                 $servers[$key] = array('uri' => $uri, 'remember' => 0);
             }
             $found = true;
             $serverId = $key;
             break;
         }
     }
     $userId = $userId == -1 ? get_current_user_id() : $userId;
     if (!$found) {
         $serverId = count($servers);
         if ($remember == 1) {
             $server = array('uri' => $uri, 'remember' => 1, 'username' => $username, 'password' => $password);
         } else {
             $server = array('uri' => $uri, 'remember' => 0);
         }
         add_user_meta($userId, 'bimsie-servers', $server);
         $servers[$serverId] = $server;
     } else {
         delete_user_meta($userId, 'bimsie-servers');
         foreach ($servers as $server) {
             add_user_meta($userId, 'bimsie-servers', $server);
         }
     }
     return $servers[$serverId];
 }
Пример #4
0
                     }
                 } else {
                     if (isset($response['error'])) {
                         $response['error'] .= '<br />' . $error;
                     } else {
                         $response['error'] = $error;
                     }
                 }
             }
         }
         $response['projects'] = $projectsLackingRevision;
     } elseif ($_POST['method'] == 'getRevisions') {
         // set this project for this issue and retrieve a list of revisions for this project from the BIMsie server
         $poid = isset($_POST['poid']) ? intval($_POST['poid']) : -1;
         $BIMsieResponse = BIMsie::request($uri, $token, 'Bimsie1ServiceInterface', 'getAllRevisionsOfProject', array('poid' => $poid));
         $error = BIMsie::getErrorMessage($BIMsieResponse);
         if ($error === false && isset($BIMsieResponse->response) && isset($BIMsieResponse->response->result)) {
             $response['revisions'] = $BIMsieResponse->response->result;
             foreach ($response['revisions'] as $key => $revision) {
                 if (isset($revision->date) && is_numeric($revision->date)) {
                     $response['revisions'][$key]->dateString = date('d-m-Y H:i', $revision->date * 0.001);
                 } else {
                     $response['revisions'][$key]->dateString = __('unknown', 'bim-bcf-management');
                 }
             }
         } else {
             $response['error'] = $error;
         }
     }
 } else {
     // We have no BIMsie server information so cannot perform request