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.
This commit is contained in:
John "Elwin" Edwards 2012-08-26 19:04:57 -07:00
parent 48b5b5d32a
commit 47cc4d29b6

View file

@ -1137,6 +1137,49 @@ function getuinfo(req, res) {
}
}
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 @@ function webHandler(req, res) {
else if (target == "/quit") {
stopgame(res, formdata);
}
else if (target.match(/^\/uinfo\//)) {
setuinfo(req, res, formdata);
}
else {
res.writeHead(405, resheaders);
res.end();