]> git.datanom.net - qtadmin.git/blobdiff - rest_client.php
prepare for wblistadm server
[qtadmin.git] / rest_client.php
index 33b9e53491bff187feab4ab4b306a04c4fd7630b..ed24278d4733f823a2fd35e3afa2ffaec27362e9 100644 (file)
@@ -25,13 +25,22 @@ require_once $CFG->root . 'lib/utils.inc.php';
 session_start();
 $util = new Utils;
 
-$ticket = $cookies = null;
-$data = 'username=mir@miras.org&password=Clara0503';
-$response = $util->RESTCall($CFG->wblistadm_url.'/ticket', $data, $cookiesIn = '');
-if ($response['http_code'] >= 200 && $response['http_code'] <= 204) {
-    $ticket = json_decode($response['content']);
-    $token = $ticket->data->CSRFPreventionToken;
-    $cookies = $response['cookies'];
+$ticket = $cookies = $data = null;
+
+if (! isset($_SESSION['ticket'])) {
+    $data = 'username=mir@miras.org&password=Clara0503';
+    $response = $util->RESTCall($CFG->wblistadm_url.'/ticket', $data, $cookiesIn = '');
+    if ($response['http_code'] >= 200 && $response['http_code'] <= 204) {
+        $_SESSION['ticket'] = json_decode($response['content']);
+        $_SESSION['CSRFPreventionToken'] = 'CSRFPreventionToken='.$_SESSION['ticket']->data->CSRFPreventionToken;
+        $_SESSION['cookies'] = $response['cookies'];
+    }
+} else {
+    $response = $util->RESTCall($CFG->wblistadm_url.'/show', $_SESSION['CSRFPreventionToken'], $cookiesIn = $_SESSION['cookies']);
+    if ($response['http_code'] >= 200 && $response['http_code'] <= 204) {
+        $data = json_decode($response['content']);
+        $_SESSION['cookies'] = $response['cookies'];
+    }
 }
 
 ?>
@@ -49,7 +58,11 @@ if ($response['http_code'] >= 200 && $response['http_code'] <= 204) {
 <pre>
 <?php
 print_r($response);
-print "Ticket: \n".var_export($ticket,true)."\nCookies: $cookies\nToken: $token";
+print "Ticket: \n".var_export($_SESSION['ticket'],true)."\nCookies: ".$_SESSION['cookies']."\nToken: ".$_SESSION['CSRFPreventionToken'];
+if (isset($data)) {
+    print "\n";
+    print_r($data);
+}
 ?>
 </pre>
 </body>
This page took 0.048637 seconds and 5 git commands to generate.