# HG changeset patch # User John "Elwin" Edwards # Date 1337748278 25200 # Node ID 5f785e1d5ccaf26fd6d769b30aa663f794a7d98e # Parent 188bbd857124e408ac4efb40b65f1ae1e3de21fd RLG-Web: set up user directories on registration Have RLG-Web create various user directories when a new user registers, as dgamelaunch does. Also add some debugging messages if registration fails. diff -r 188bbd857124 -r 5f785e1d5cca rlgwebd.js --- a/rlgwebd.js Tue May 22 20:54:33 2012 -0700 +++ b/rlgwebd.js Tue May 22 21:44:38 2012 -0700 @@ -327,6 +327,17 @@ return; } +/* Sets things up for a new user, like dgamelaunch's commands[register] */ +function regsetup(username) { + function regsetup_l2(err) { + for (var g in games) { + fs.mkdir(path.join("/dgldir/ttyrec", username, games[g].uname), 0755); + } + } + fs.mkdir(path.join("/dgldir/userdata", username), 0755); + fs.mkdir(path.join("/dgldir/ttyrec/", username), 0755, regsetup_l2); +} + function register(req, res, formdata) { var uname, passwd, email; if (typeof (formdata.name) != "string" || formdata.name === "") { @@ -348,18 +359,25 @@ else email = formdata["email"]; function checkreg(code, signal) { - if (code == 4) + if (code == 4) { sendError(res, 2, "Invalid characters in name or email."); - else if (code == 1) + console.log("Attempted registration: " + uname + " " + email); + } + else if (code == 1) { sendError(res, 2, "Username " + uname + " is already being used."); - else if (code != 0) + console.log("Attempted duplicate registration: " + uname); + } + else if (code != 0) { sendError(res, 0, null); + console.log("sqlickrypt register failed with code " + code); + } else { res.writeHead(200, {'Content-Type': 'text/plain'}); var reply = {"t": "r", "d": uname}; res.write(JSON.stringify(reply)); res.end(); console.log("Added new user: " + uname); + regsetup(uname); } } var child_adder = child_process.spawn("/bin/sqlickrypt", ["register"]);