a working authd/authclient - mostly
authorpaulr <me@pjr.cc>
Sun, 5 Dec 2010 14:23:32 +0000 (01:23 +1100)
committerpaulr <me@pjr.cc>
Sun, 5 Dec 2010 14:23:32 +0000 (01:23 +1100)
authserver/authd/authd.php
authserver/authd/gaasdata.sqlite [new file with mode: 0644]
authserver/lib/authClient.php
authserver/usercmd.php
lib/ga4php.php

index 2474b3a..afe3883 100644 (file)
@@ -76,7 +76,11 @@ if($pid == -1) {
                                } else {
                                        $username = $msg["username"];                           
                                        global $myga;
-                                       msg_send($cl_queue, MSG_DELETE_USER, $myga->deleteUser($username));
+                                       $sql = "delete from users where users_username='$username'";
+                                       $dbo = getDatabase();
+                                       $dbo->query($sql);
+
+                                       msg_send($cl_queue, MSG_DELETE_USER, true);
                                }
                                break;
                        case MSG_AUTH_USER_PASSWORD:
@@ -177,8 +181,10 @@ if($pid == -1) {
                                }
                                
                                global $myga;
-                               $myga->setUserKey($username, $passcode);
-                               msg_send($cl_queue, MSG_SET_USER_TOKEN, $myga->createUrl($username));
+                               $username = $msg["username"];
+                               $token = $msg["tokenstring"];
+                               $return = $myga->setUserKey($username, $token);
+                               msg_send($cl_queue, MSG_SET_USER_TOKEN, $return);
                                
                                // TODO now set token 
                                break;                  
diff --git a/authserver/authd/gaasdata.sqlite b/authserver/authd/gaasdata.sqlite
new file mode 100644 (file)
index 0000000..d9792ca
Binary files /dev/null and b/authserver/authd/gaasdata.sqlite differ
index 677be24..a29af89 100644 (file)
@@ -21,16 +21,12 @@ class GAAuthClient {
                $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
                
                $message["username"] = $username;
-               $message["token"] = $token;
+               $message["tokenstring"] = $token;
                
                msg_send($sr_queue, MSG_SET_USER_TOKEN, $message, true, true, $msg_err);
-               echo "message sent\n";
                
                msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
-               echo "message received?\n";
-               print_r($msg);
-               
-               
+               return $msg;            
        }
        
        function setUserPass($username, $password) {
@@ -53,12 +49,10 @@ class GAAuthClient {
                $message["password"] = $password;
                
                msg_send($sr_queue, MSG_SET_USER_PASSWORD, $message, true, true, $msg_err);
-               echo "message sent\n";
                
                msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
-               echo "message received?\n";
-               print_r($msg);          
-       
+
+               return $msg;
        }
        
        function authUserPass($username, $password) {
@@ -81,12 +75,9 @@ class GAAuthClient {
                $message["password"] = $password;
                
                msg_send($sr_queue, MSG_AUTH_USER_PASSWORD, $message, true, true, $msg_err);
-               echo "message sent\n";
                
                msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
-               echo "message received?\n";
-               print_r($msg);
-               
+               return $msg;            
        }
        
        function deleteUser($username) {
@@ -108,11 +99,10 @@ class GAAuthClient {
                $message["username"] = $username;
                
                msg_send($sr_queue, MSG_DELETE_USER, $message, true, true, $msg_err);
-               echo "message sent\n";
                
                msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
-               echo "message received?\n";
-               print_r($msg);
+               
+               return $msg;
                
        }
        
@@ -136,12 +126,9 @@ class GAAuthClient {
                $message["realname"] = $realname;
                
                msg_send($sr_queue, MSG_SET_USER_REALNAME, $message, true, true, $msg_err);
-               echo "message sent\n";
                
                msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
-               echo "message received?\n";
-               print_r($msg);
-               
+               return $msg;            
        }
        
        function getUsers() {
@@ -161,11 +148,8 @@ class GAAuthClient {
                $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
                
                msg_send($sr_queue, MSG_GET_USERS, "", true, true, $msg_err);
-               echo "message sent\n";
                
                msg_receive($cl_queue, 0, $msg_type, 524288, $msg);
-               echo "message received?\n";
-               print_r($msg);
                
                return $msg;
        }
@@ -227,7 +211,7 @@ class GAAuthClient {
                return $msg;
        }
 
-       function setTokenType($username, $tokentype) {
+       function setUserTokenType($username, $tokentype) {
                global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
                
                
@@ -249,12 +233,9 @@ class GAAuthClient {
                $message["username"] = $username;
                $message["tokentype"] = $tokentype;
                
-               msg_send($sr_queue, MSG_ADD_USER, $message, true, true, $msg_err);
-               echo "message sent\n";
+               msg_send($sr_queue, MSG_SET_USER_TOKEN_TYPE, $message, true, true, $msg_err);
                
                msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
-               echo "message received?\n";
-               print_r($msg);
                
                return $msg;
                
index 289922a..e58cd65 100644 (file)
@@ -41,9 +41,9 @@ if(!isset($argv[1])) {
 switch($argv[1]) {
        case "auth":
                if($myAC->authUserToken($argv[2], $argv[3])==1) {
-                       echo "Pass!";
+                       echo "Pass!\n";
                } else {
-                       echo "Fail!";
+                       echo "Fail!\n";
                }
                break;
        case "add":
@@ -51,25 +51,55 @@ switch($argv[1]) {
                echo "Created user, ".$argv[2]." returned $return\n";
                break;
        case "delete":
-               $myAC->deleteUser($argv[2]);
+               $res = $myAC->deleteUser($argv[2]);
+               if($res) {
+                       echo "Deleted\n";
+               } else {
+                       echo "Failure?\n";
+               }
                break;
        case "authpass":
-               $myAC->authUserPass($argv[2], $argv[3]);
+               $ret = $myAC->authUserPass($argv[2], $argv[3]);
+               if($ret) echo "Authenticated\n";
+               else echo "Failed\n";
                break;
        case "setpass":
-               $myAC->setUserPass($argv[2], $argv[3]);
+               $res = $myAC->setUserPass($argv[2], $argv[3]);
+               if($res) echo "Password Set\n";
+               else echo "Failure?\n";
                break;
        case "setname":
-               $myAC->setUserRealName($argv[2], $argv[3]);
+               $ret = $myAC->setUserRealName($argv[2], $argv[3]);
+               if($ret) echo "Real Name Set\n";
+               else echo "Failure?\n";
                break;
        case "settoken":
-               $myAC->setUserToken($argv[2], $argv[3]);
+               $ret = $myAC->setUserToken($argv[2], $argv[3]);
+               if($ret) echo "Token Set\n";
+               else echo "Failure?\n";
                break;
        case "settype":
-               $myAC->setUserTokenType($argv[2], $argv[3]);
+               $ret = $myAC->setUserTokenType($argv[2], $argv[3]);
+               if($ret) echo "Token Type Set\n";
+               else echo "Failure?\n";
                break;
        case "getusers":
-               $myAC->getUsers();
+               $users = $myAC->getUsers();
+               foreach($users as $user) {
+                       if($user["realname"] != "") $realname = $user["realname"];
+                       else $realname = "- Not Set -";
+                       
+                       if($user["haspass"]) $haspass = "Yes";
+                       else $haspass = "No";
+                       
+                       if($user["hastoken"]) $hastoken = "Yes";
+                       else $hastoken = "No";
+                       
+                       echo "Username: ".$user["username"]."\n";
+                       echo "\tReal Name: ".$realname."\n";
+                       echo "\tHas Password?: ".$haspass."\n";
+                       echo "\tHas Token?: ".$hastoken."\n\n";
+               }
                break;
 }
 ?>
\ No newline at end of file
index 3435d03..6c4e156 100644 (file)
@@ -112,7 +112,10 @@ abstract class GoogleAuthenticator {
                // consider scrapping this
                $token = $this->internalGetData($username);
                $token["tokenkey"] = $key;
-               $this->internalPutData($username, $token);              
+               $this->internalPutData($username, $token);
+               
+               // TODO error checking
+               return true;
        }