RLG-Web: add user registration
Update the server and client sides of RLG-Web to make use of the new registration feature of sqlickrypt.
This commit is contained in:
parent
dfbd2a71d0
commit
e36f058daf
4 changed files with 130 additions and 4 deletions
46
rlgwebd.js
46
rlgwebd.js
|
|
@ -321,12 +321,53 @@ function login(req, res, formdata) {
|
|||
});
|
||||
}
|
||||
/* 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 @@ function handler(req, res) {
|
|||
else if (target == "/login") {
|
||||
login(req, res, formdata);
|
||||
}
|
||||
else if (target == "/addacct") {
|
||||
register(req, res, formdata);
|
||||
}
|
||||
else {
|
||||
res.writeHead(405, resheaders);
|
||||
res.end();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue