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.
This commit is contained in:
John "Elwin" Edwards 2012-08-13 09:07:28 -07:00
parent acae714a6b
commit 81e772545a

View file

@ -1092,6 +1092,46 @@ function pstatusmsg(req, res) {
}); });
} }
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", var errorcodes = [ "Generic Error", "Not logged in", "Invalid data",
"Login failed", "Already playing", "Game launch failed", "Login failed", "Already playing", "Game launch failed",
"Server shutting down", "Game not in progress" ]; "Server shutting down", "Game not in progress" ];
@ -1112,7 +1152,6 @@ function sendError(res, ecode, msg, box) {
res.end(); res.end();
} }
// TODO new-objects done to here
function webHandler(req, res) { function webHandler(req, res) {
/* default headers for the response */ /* default headers for the response */
var resheaders = {'Content-Type': 'text/html'}; var resheaders = {'Content-Type': 'text/html'};
@ -1192,6 +1231,9 @@ function webHandler(req, res) {
else if (target == '/status') { else if (target == '/status') {
statusmsg(req, res); statusmsg(req, res);
} }
else if (target == '/uinfo') {
getuinfo(req, res);
}
else if (target.match(/^\/pstatus\//)) { else if (target.match(/^\/pstatus\//)) {
pstatusmsg(req, res); pstatusmsg(req, res);
} }