} 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:
}
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;
$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) {
$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) {
$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) {
$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;
}
$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() {
$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;
}
return $msg;
}
- function setTokenType($username, $tokentype) {
+ function setUserTokenType($username, $tokentype) {
global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
$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;
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":
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