changeset 124:fbeb0bf2b51d

Add a user information interface at /uinfo. User information can be retrieved at /uinfo?key=<login key>&<prop>. The only property currently retrievable is email; eventually these will also be settable via POST.
author John "Elwin" Edwards <elwin@sdf.org>
date Mon, 13 Aug 2012 09:07:28 -0700
parents 0a3ff1267c24
children 5ad15380f851
files rlgwebd.js
diffstat 1 files changed, 43 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rlgwebd.js	Mon Aug 13 08:53:46 2012 -0700
+++ b/rlgwebd.js	Mon Aug 13 09:07:28 2012 -0700
@@ -1092,6 +1092,46 @@
   });
 }
 
+function getuinfo(req, res) {
+  var query = url.parse(req.url, true).query;
+  if (!("key" in query) || !(query["key"] in logins)) {
+    sendError(res, 1);
+    return;
+  }
+  var name = logins[query["key"]].name;
+  var reply = { "u": name };
+  function send() {
+    res.writeHead(200, { "Content-Type": "application/json" });
+    res.write(JSON.stringify(reply));
+    res.end();
+  }
+  if ("pw" in query) {
+    /* Don't actually divulge passwords. */
+    reply["pw"] = "";
+  }
+  if ("email" in query) {
+    var address;
+    function finish(code, signal) {
+      if (code != 0) {
+        tslog("sqlickrypt: %d with name %s", code, name);
+        sendError(res, 2);
+      }
+      else {
+        reply["email"] = address;
+        send();
+      }
+    }
+    var subproc = child_process.spawn("/bin/sqlickrypt", ["getmail"]);
+    subproc.stdout.on("data", function (data) {
+      address = data.toString().replace(/\n/g, "");
+    });
+    subproc.on("exit", finish);
+    subproc.stdin.end(name + '\n', "utf8");
+  }
+  else
+    send();
+}
+
 var errorcodes = [ "Generic Error", "Not logged in", "Invalid data", 
         "Login failed", "Already playing", "Game launch failed",
         "Server shutting down", "Game not in progress" ];
@@ -1112,7 +1152,6 @@
   res.end();
 }
 
-// TODO new-objects done to here
 function webHandler(req, res) {
   /* default headers for the response */
   var resheaders = {'Content-Type': 'text/html'};
@@ -1192,6 +1231,9 @@
       else if (target == '/status') {
         statusmsg(req, res);
       }
+      else if (target == '/uinfo') {
+        getuinfo(req, res);
+      }
       else if (target.match(/^\/pstatus\//)) {
         pstatusmsg(req, res);
       }