Mercurial > hg > rlgwebd
diff rlgwebd.js @ 19:188bbd857124
RLG-Web: add user registration
Update the server and client sides of RLG-Web to make use of the new
registration feature of sqlickrypt.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Tue, 22 May 2012 20:54:33 -0700 |
parents | d3e3d6b4016b |
children | 5f785e1d5cca |
line wrap: on
line diff
--- a/rlgwebd.js Mon May 21 21:40:56 2012 -0700 +++ b/rlgwebd.js Tue May 22 20:54:33 2012 -0700 @@ -321,12 +321,53 @@ }); } /* Launch the sqlickrypt utility to check the password. */ - var checker = require('child_process').spawn("/bin/sqlickrypt"); + var checker = child_process.spawn("/bin/sqlickrypt", ["check"]); checker.on("exit", checkit); checker.stdin.end(username + '\n' + password + '\n', "utf8"); return; } +function register(req, res, formdata) { + var uname, passwd, email; + if (typeof (formdata.name) != "string" || formdata.name === "") { + sendError(res, 2, "No name given."); + return; + } + else + uname = formdata["name"]; + if (typeof (formdata.pw) != "string" || formdata.pw === "") { + sendError(res, 2, "No password given."); + return; + } + else + passwd = formdata["pw"]; + if (typeof (formdata.email) != "string" || formdata.email === "") { + /* E-mail is optional */ + email = "nobody@nowhere.not"; + } + else + email = formdata["email"]; + function checkreg(code, signal) { + if (code == 4) + sendError(res, 2, "Invalid characters in name or email."); + else if (code == 1) + sendError(res, 2, "Username " + uname + " is already being used."); + else if (code != 0) + sendError(res, 0, null); + 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); + } + } + var child_adder = child_process.spawn("/bin/sqlickrypt", ["register"]); + child_adder.on("exit", checkreg); + child_adder.stdin.end(uname + '\n' + passwd + '\n' + email + '\n', "utf8"); + return; +} + function logout(term, res) { if (!term.alive) { sendError(res, 1, null); @@ -482,6 +523,9 @@ else if (target == "/login") { login(req, res, formdata); } + else if (target == "/addacct") { + register(req, res, formdata); + } else { res.writeHead(405, resheaders); res.end();