# HG changeset patch # User John "Elwin" Edwards # Date 1344874048 25200 # Node ID fbeb0bf2b51dbadf6f31a0daf5b0d32fcafc613d # Parent 0a3ff1267c243c3f9f9c0723e7c9032845cc2b6a Add a user information interface at /uinfo. User information can be retrieved at /uinfo?key=&. The only property currently retrievable is email; eventually these will also be settable via POST. diff -r 0a3ff1267c24 -r fbeb0bf2b51d rlgwebd.js --- 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); }