print_r($msg);
switch($msg_type) {
case MSG_AUTH_USER_TOKEN:
+ echo "Call to auth user token\n";
// minimal checking, we leav it up to authenticateUser to do the real
// checking
if(!isset($msg["user"])) $msg["user"] = "";
msg_send($cl_queue, MSG_AUTH_USER_TOKEN, $myga->authenticateUser($username, $passcode));
break;
case MSG_ADD_USER_TOKEN:
+ echo "Call to add user token\n";
if(!isset($msg["username"])) {
msg_send($cl_queue, MSG_ADD_USER_TOKEN, false);
} else {
}
break;
case MSG_DELETE_USER:
+ echo "Call to del user\n";
if(!isset($msg["username"])) {
msg_send($cl_queue, MSG_DELETE_USER, false);
} else {
}
case MSG_AUTH_USER_PASSWORD:
// TODO
+ echo "Call to auth user pass\n";
if(!isset($msg["username"])) {
msg_send($cl_queue, MSG_AUTH_USER_PASSWORD, false);
break;
}
$username = $msg["username"];
- $sql = "select users_password from users where username='$username'";
+ $password = $msg["password"];
+ $sql = "select users_password from users where users_username='$username'";
$dbo = getDatabase();
-
+ $res = $dbo->query($sql);
+ $pass = "";
+ foreach($res as $row) {
+ $pass = $row["users_password"];
+ }
// TODO now do auth
+ $ourpass = hash('sha512', $password);
+ echo "ourpass: $ourpass\nourhash: $pass\n";
+ if($ourpass == $pass) {
+ msg_send($cl_queue, MSG_AUTH_USER_PASSWORD, true);
+
+ } else {
+ msg_send($cl_queue, MSG_AUTH_USER_PASSWORD, false);
+
+ }
break;
case MSG_SET_USER_PASSWORD:
+ echo "Call to set user pass\n";
// TODO
if(!isset($msg["username"])) {
msg_send($cl_queue, MSG_SET_USER_PASSWORD, false);
break;
}
+ $username = $msg["username"];
+ $password = $msg["password"];
+
+ $pass = hash('sha512', $password);
+
+ $dbo = getDatabase();
+ $sql = "update users set users_password='$pass' where users_username='$username'";
+
+ $dbo->query($sql);
+
+ msg_send($cl_queue, MSG_SET_USER_REALNAME, true);
+
+
// these are irrelavent yet
// TODO now set pass
break;
case MSG_SET_USER_REALNAME:
+ echo "Call to set user realname\n";
// TODO
if(!isset($msg["username"])) {
msg_send($cl_queue, MSG_SET_USER_REALNAME, false);
$username = $msg["username"];
$realname = $msg["realname"];
- $sql = "update set users_realnemd='$realname' where username='$username'";
+ $sql = "update users set users_realname='$realname' where users_username='$username'";
+ echo "sql: $sql\n";
$dbo = getDatabase();
$dbo->query($sql);
break;
case MSG_SET_USER_TOKEN:
// TODO
+ echo "Call to set user token\n";
if(!isset($msg["username"])) {
msg_send($cl_queue, MSG_SET_USER_TOKEN, false);
break;
break;
case MSG_SET_USER_TOKEN_TYPE:
// TODO
+ echo "Call to set user token type\n";
if(!isset($msg["username"])) {
msg_send($cl_queue, MSG_SET_USER_TOKEN_TYPE, false);
break;
$cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
$sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+ $message["username"] = $username;
+ $message["token"] = $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);
+
+
}
function setUserPass($username, $password) {
$cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
$sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
+ $message["username"] = $username;
+ $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);
+
}
function authUserPass($username, $password) {
$cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
$sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
+ $message["username"] = $username;
+ $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);
}
$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, $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);
}
$cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
$sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
+ $message["username"] = $username;
+ $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);
}
$sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
- $message["user"] = $username;
+ $message["username"] = $username;
$message["passcode"] = $passcode;
msg_send($sr_queue, MSG_AUTH_USER, $message, true, true, $msg_err);
$message["username"] = $username;
- msg_send($sr_queue, MSG_ADD_USER, $message, true, true, $msg_err);
+ msg_send($sr_queue, MSG_ADD_USER_TOKEN, $message, true, true, $msg_err);
echo "message sent\n";
msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
$sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
$message["username"] = $username;
+ $message["tokentype"] = $tokentype;
+
+ msg_send($sr_queue, MSG_ADD_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;
}
}