# HG changeset patch # User John "Elwin" Edwards # Date 1346033097 25200 # Node ID 3e3824711791d761a1d2f4eec76bc3c078f258de # Parent 5ad15380f8511262136acda989dad31563138f63 RLG-Web server: allow changing e-mail and password. Logged-in users can change their e-mail addresses and passwords with a POST to the /uinfo interface. diff -r 5ad15380f851 -r 3e3824711791 rlgwebd.js --- a/rlgwebd.js Sat Aug 25 19:33:31 2012 -0700 +++ b/rlgwebd.js Sun Aug 26 19:04:57 2012 -0700 @@ -1137,6 +1137,49 @@ } } +function setuinfo(req, res, postdata) { + var urlobj = url.parse(req.url, true); + var query = urlobj.query; + if (!("key" in query) || !(query["key"] in logins)) { + sendError(res, 1); + return; + } + var name = logins[query["key"]].name; + var match = urlobj.pathname.match(/^\/[^\/]*\/(.*)/); + if (!match || !match[1]) { + send404(res, urlobj.pathname, true); + return; + } + var which = match[1]; + if (!("v" in postdata)) { + sendError(res, 2, "No value provided"); + return; + } + if (which == "email" || which == "pw") { + var args; + if (which == "email") + args = ["setmail"]; + else + args = ["setpw"]; + var child = child_process.execFile("/bin/sqlickrypt", args, + function (err, stdout, stderr) { + if (err) { + tslog("Could not set %s: sqlickrypt error %d", which, err.code); + sendError(res, 2); + } + else { + tslog("User %s has changed %s", name, which); + res.writeHead(200, { "Content-Type": "application/json" }); + res.end(JSON.stringify({"t": "t"})); + } + }); + child.stdin.end(name + "\n" + postdata.v + "\n", "utf8"); + } + else { + send404(res, urlobj.pathname, true); + } +} + var errorcodes = [ "Generic Error", "Not logged in", "Invalid data", "Login failed", "Already playing", "Game launch failed", "Server shutting down", "Game not in progress" ]; @@ -1227,6 +1270,9 @@ else if (target == "/quit") { stopgame(res, formdata); } + else if (target.match(/^\/uinfo\//)) { + setuinfo(req, res, formdata); + } else { res.writeHead(405, resheaders); res.end();