Mercurial > hg > rlgwebd
comparison 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 |
comparison
equal
deleted
inserted
replaced
18:59ea628abb81 | 19:188bbd857124 |
---|---|
318 | 318 |
319 function setup() { | 319 function setup() { |
320 keyHexCodes.init(); | 320 keyHexCodes.init(); |
321 termemu.init("termwrap", 24, 80); | 321 termemu.init("termwrap", 24, 80); |
322 setTitle("Not connected."); | 322 setTitle("Not connected."); |
323 setmode("login"); | |
323 return; | 324 return; |
324 } | 325 } |
325 | 326 |
326 function toggleshift() { | 327 function toggleshift() { |
327 termemu.toggleshift(); | 328 termemu.toggleshift(); |
362 /* Success */ | 363 /* Success */ |
363 termemu.sessid = reply.id; | 364 termemu.sessid = reply.id; |
364 termemu.resize(reply.h, reply.w); | 365 termemu.resize(reply.h, reply.w); |
365 setTitle("Playing as " + loginmsg["name"]); | 366 setTitle("Playing as " + loginmsg["name"]); |
366 debug(1, "Logged in with id " + termemu.sessid); | 367 debug(1, "Logged in with id " + termemu.sessid); |
367 document.getElementById("loginform").style.display = "none"; | 368 //document.getElementById("loginform").style.display = "none"; |
369 setmode("play"); | |
368 getData(); | 370 getData(); |
369 } | 371 } |
370 else if (reply.t == 'E') { | 372 else if (reply.t == 'E') { |
371 debug(1, "Could not start game: " + reply.s); | 373 debug(1, "Could not start game: " + reply.s); |
372 document.getElementById("input_name").value = ""; | 374 document.getElementById("input_name").value = ""; |
373 document.getElementById("input_pw").value = ""; | 375 document.getElementById("input_pw").value = ""; |
374 } | 376 } |
375 }; | 377 }; |
376 req.open('POST', '/login', true); | 378 req.open('POST', '/login', true); |
377 req.send(JSON.stringify(loginmsg)); | 379 req.send(JSON.stringify(loginmsg)); |
380 return; | |
381 } | |
382 | |
383 function formreg(ev) { | |
384 ev.preventDefault(); | |
385 if (termemu.sessid != null) | |
386 return; | |
387 var regmsg = {}; | |
388 regmsg["name"] = document.getElementById("regin_name").value; | |
389 regmsg["pw"] = document.getElementById("regin_pw").value; | |
390 regmsg["email"] = document.getElementById("regin_email").value; | |
391 var req = new XMLHttpRequest(); | |
392 req.onreadystatechange = function () { | |
393 if (req.readyState != 4 || req.status != 200) | |
394 return; | |
395 var reply = JSON.parse(req.responseText); | |
396 if (reply.t == 'r') { | |
397 /* Success */ | |
398 debug(1, "Registered account: " + reply.d); | |
399 setmode("login"); | |
400 } | |
401 else if (reply.t == 'E') { | |
402 debug(1, "Could not register: " + reply.s); | |
403 document.getElementById("regin_name").value = ""; | |
404 document.getElementById("regin_pw").value = ""; | |
405 document.getElementById("regin_email").value = ""; | |
406 } | |
407 }; | |
408 req.open('POST', '/addacct', true); | |
409 req.send(JSON.stringify(regmsg)); | |
378 return; | 410 return; |
379 } | 411 } |
380 | 412 |
381 function logout() { | 413 function logout() { |
382 if (termemu.sessid == null) | 414 if (termemu.sessid == null) |
384 termemu.sessid = null; | 416 termemu.sessid = null; |
385 setTitle("Game over."); | 417 setTitle("Game over."); |
386 nsend = 0; | 418 nsend = 0; |
387 nrecv = 0; | 419 nrecv = 0; |
388 msgQ = []; | 420 msgQ = []; |
389 document.getElementById("loginform").style.display = "block"; | 421 //document.getElementById("loginform").style.display = "block"; |
422 setform("login"); | |
390 return; | 423 return; |
391 } | 424 } |
392 | 425 |
393 function stop() { | 426 function stop() { |
394 var req = new XMLHttpRequest(); | 427 var req = new XMLHttpRequest(); |
399 } | 432 } |
400 }; | 433 }; |
401 req.open('POST', '/feed', true); | 434 req.open('POST', '/feed', true); |
402 req.send(JSON.stringify({"id": termemu.sessid, "t": "q"})); | 435 req.send(JSON.stringify({"id": termemu.sessid, "t": "q"})); |
403 return; | 436 return; |
437 } | |
438 | |
439 function setmode(mode, ev) { | |
440 if (ev) | |
441 ev.preventDefault(); | |
442 if (mode == "play") { | |
443 document.getElementById("keyboard").style.display = "block"; | |
444 document.getElementById("login").style.display = "none"; | |
445 document.getElementById("register").style.display = "none"; | |
446 } | |
447 else if (mode == "login") { | |
448 document.getElementById("keyboard").style.display = "none"; | |
449 document.getElementById("login").style.display = "block"; | |
450 document.getElementById("register").style.display = "none"; | |
451 } | |
452 else if (mode == "register") { | |
453 document.getElementById("keyboard").style.display = "none"; | |
454 document.getElementById("login").style.display = "none"; | |
455 document.getElementById("register").style.display = "block"; | |
456 } | |
404 } | 457 } |
405 | 458 |
406 function debug(level, msg) { | 459 function debug(level, msg) { |
407 if (level < debugSuppress) | 460 if (level < debugSuppress) |
408 return; | 461 return; |