Mercurial > hg > rlgwebd
diff rlgterm.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 | ef6127ed6da3 |
children | 82be54381964 |
line wrap: on
line diff
--- a/rlgterm.js Mon May 21 21:40:56 2012 -0700 +++ b/rlgterm.js Tue May 22 20:54:33 2012 -0700 @@ -320,6 +320,7 @@ keyHexCodes.init(); termemu.init("termwrap", 24, 80); setTitle("Not connected."); + setmode("login"); return; } @@ -364,7 +365,8 @@ termemu.resize(reply.h, reply.w); setTitle("Playing as " + loginmsg["name"]); debug(1, "Logged in with id " + termemu.sessid); - document.getElementById("loginform").style.display = "none"; + //document.getElementById("loginform").style.display = "none"; + setmode("play"); getData(); } else if (reply.t == 'E') { @@ -378,6 +380,36 @@ return; } +function formreg(ev) { + ev.preventDefault(); + if (termemu.sessid != null) + return; + var regmsg = {}; + regmsg["name"] = document.getElementById("regin_name").value; + regmsg["pw"] = document.getElementById("regin_pw").value; + regmsg["email"] = document.getElementById("regin_email").value; + var req = new XMLHttpRequest(); + req.onreadystatechange = function () { + if (req.readyState != 4 || req.status != 200) + return; + var reply = JSON.parse(req.responseText); + if (reply.t == 'r') { + /* Success */ + debug(1, "Registered account: " + reply.d); + setmode("login"); + } + else if (reply.t == 'E') { + debug(1, "Could not register: " + reply.s); + document.getElementById("regin_name").value = ""; + document.getElementById("regin_pw").value = ""; + document.getElementById("regin_email").value = ""; + } + }; + req.open('POST', '/addacct', true); + req.send(JSON.stringify(regmsg)); + return; +} + function logout() { if (termemu.sessid == null) return; @@ -386,7 +418,8 @@ nsend = 0; nrecv = 0; msgQ = []; - document.getElementById("loginform").style.display = "block"; + //document.getElementById("loginform").style.display = "block"; + setform("login"); return; } @@ -403,6 +436,26 @@ return; } +function setmode(mode, ev) { + if (ev) + ev.preventDefault(); + if (mode == "play") { + document.getElementById("keyboard").style.display = "block"; + document.getElementById("login").style.display = "none"; + document.getElementById("register").style.display = "none"; + } + else if (mode == "login") { + document.getElementById("keyboard").style.display = "none"; + document.getElementById("login").style.display = "block"; + document.getElementById("register").style.display = "none"; + } + else if (mode == "register") { + document.getElementById("keyboard").style.display = "none"; + document.getElementById("login").style.display = "none"; + document.getElementById("register").style.display = "block"; + } +} + function debug(level, msg) { if (level < debugSuppress) return;