diff rlgwebd.js @ 20:5f785e1d5cca

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.
author John "Elwin" Edwards <elwin@sdf.org>
date Tue, 22 May 2012 21:44:38 -0700
parents 188bbd857124
children 51d59a0e3b20
line wrap: on
line diff
--- 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"]);