comparison 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
comparison
equal deleted inserted replaced
19:188bbd857124 20:5f785e1d5cca
325 checker.on("exit", checkit); 325 checker.on("exit", checkit);
326 checker.stdin.end(username + '\n' + password + '\n', "utf8"); 326 checker.stdin.end(username + '\n' + password + '\n', "utf8");
327 return; 327 return;
328 } 328 }
329 329
330 /* Sets things up for a new user, like dgamelaunch's commands[register] */
331 function regsetup(username) {
332 function regsetup_l2(err) {
333 for (var g in games) {
334 fs.mkdir(path.join("/dgldir/ttyrec", username, games[g].uname), 0755);
335 }
336 }
337 fs.mkdir(path.join("/dgldir/userdata", username), 0755);
338 fs.mkdir(path.join("/dgldir/ttyrec/", username), 0755, regsetup_l2);
339 }
340
330 function register(req, res, formdata) { 341 function register(req, res, formdata) {
331 var uname, passwd, email; 342 var uname, passwd, email;
332 if (typeof (formdata.name) != "string" || formdata.name === "") { 343 if (typeof (formdata.name) != "string" || formdata.name === "") {
333 sendError(res, 2, "No name given."); 344 sendError(res, 2, "No name given.");
334 return; 345 return;
346 email = "nobody@nowhere.not"; 357 email = "nobody@nowhere.not";
347 } 358 }
348 else 359 else
349 email = formdata["email"]; 360 email = formdata["email"];
350 function checkreg(code, signal) { 361 function checkreg(code, signal) {
351 if (code == 4) 362 if (code == 4) {
352 sendError(res, 2, "Invalid characters in name or email."); 363 sendError(res, 2, "Invalid characters in name or email.");
353 else if (code == 1) 364 console.log("Attempted registration: " + uname + " " + email);
365 }
366 else if (code == 1) {
354 sendError(res, 2, "Username " + uname + " is already being used."); 367 sendError(res, 2, "Username " + uname + " is already being used.");
355 else if (code != 0) 368 console.log("Attempted duplicate registration: " + uname);
369 }
370 else if (code != 0) {
356 sendError(res, 0, null); 371 sendError(res, 0, null);
372 console.log("sqlickrypt register failed with code " + code);
373 }
357 else { 374 else {
358 res.writeHead(200, {'Content-Type': 'text/plain'}); 375 res.writeHead(200, {'Content-Type': 'text/plain'});
359 var reply = {"t": "r", "d": uname}; 376 var reply = {"t": "r", "d": uname};
360 res.write(JSON.stringify(reply)); 377 res.write(JSON.stringify(reply));
361 res.end(); 378 res.end();
362 console.log("Added new user: " + uname); 379 console.log("Added new user: " + uname);
380 regsetup(uname);
363 } 381 }
364 } 382 }
365 var child_adder = child_process.spawn("/bin/sqlickrypt", ["register"]); 383 var child_adder = child_process.spawn("/bin/sqlickrypt", ["register"]);
366 child_adder.on("exit", checkreg); 384 child_adder.on("exit", checkreg);
367 child_adder.stdin.end(uname + '\n' + passwd + '\n' + email + '\n', "utf8"); 385 child_adder.stdin.end(uname + '\n' + passwd + '\n' + email + '\n', "utf8");