set token types
[ga4php.git] / authserver / lib / authClient.php
index 58de4ec..ba6c2ff 100644 (file)
@@ -3,6 +3,55 @@
 require_once("lib.php");
 
 class GAAuthClient {
+       function syncUserToken($username, $tokenone, $tokentwo) {
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
+               
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+               
+               $message["username"] = $username;
+               $message["tokenone"] = $tokenone;
+               $message["tokentwo"] = $tokentwo;
+
+               msg_send($sr_queue, MSG_SYNC_TOKEN, $message, true, true, $msg_err);
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               return $msg;            
+               
+       }
+       
+       function getUserTokenType($username) {
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
+               
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+               
+               $message["username"] = $username;
+               msg_send($sr_queue, MSG_GET_TOKEN_TYPE, $message, true, true, $msg_err);
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               return $msg;            
+       }
        
        function setUserToken($username, $token) {
                global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
@@ -55,7 +104,7 @@ class GAAuthClient {
                return $msg;
        }
        
-       function getOtkPng($username) {
+       function getOtkID($username) {
                global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
                
                
@@ -72,6 +121,33 @@ class GAAuthClient {
                $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
 
                $message["username"] = $username;
+               msg_send($sr_queue, MSG_GET_OTK_ID, $message, true, true, $msg_err);
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               
+               return $msg;
+               
+       }
+       
+       function getOtkPng($username, $otk) {
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
+               
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
+               $message["otk"] = $otk;
+               $message["username"] = $username;
+               error_log("sending message, $otk");
                msg_send($sr_queue, MSG_GET_OTK_PNG, $message, true, true, $msg_err);
                
                msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
@@ -200,7 +276,33 @@ class GAAuthClient {
                $message["passcode"] = $passcode;
                
                msg_send($sr_queue, MSG_AUTH_USER_TOKEN, $message, true, true, $msg_err);
-               echo "message sent\n";
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               
+               return $msg;
+       }
+       
+       function deleteUserToken($username) {
+               
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+               
+               
+               $message["username"] = $username;
+               
+               msg_send($sr_queue, MSG_DELETE_USER_TOKEN, $message, true, true, $msg_err);
                
                msg_receive($cl_queue, 0, $msg_type, 16384, $msg);