comparison rlgwebd.js @ 124:fbeb0bf2b51d

Add a user information interface at /uinfo. User information can be retrieved at /uinfo?key=<login key>&<prop>. The only property currently retrievable is email; eventually these will also be settable via POST.
author John "Elwin" Edwards <elwin@sdf.org>
date Mon, 13 Aug 2012 09:07:28 -0700
parents 077adfeea038
children 5ad15380f851
comparison
equal deleted inserted replaced
123:0a3ff1267c24 124:fbeb0bf2b51d
1090 res.write(JSON.stringify(reply)); 1090 res.write(JSON.stringify(reply));
1091 res.end(); 1091 res.end();
1092 }); 1092 });
1093 } 1093 }
1094 1094
1095 function getuinfo(req, res) {
1096 var query = url.parse(req.url, true).query;
1097 if (!("key" in query) || !(query["key"] in logins)) {
1098 sendError(res, 1);
1099 return;
1100 }
1101 var name = logins[query["key"]].name;
1102 var reply = { "u": name };
1103 function send() {
1104 res.writeHead(200, { "Content-Type": "application/json" });
1105 res.write(JSON.stringify(reply));
1106 res.end();
1107 }
1108 if ("pw" in query) {
1109 /* Don't actually divulge passwords. */
1110 reply["pw"] = "";
1111 }
1112 if ("email" in query) {
1113 var address;
1114 function finish(code, signal) {
1115 if (code != 0) {
1116 tslog("sqlickrypt: %d with name %s", code, name);
1117 sendError(res, 2);
1118 }
1119 else {
1120 reply["email"] = address;
1121 send();
1122 }
1123 }
1124 var subproc = child_process.spawn("/bin/sqlickrypt", ["getmail"]);
1125 subproc.stdout.on("data", function (data) {
1126 address = data.toString().replace(/\n/g, "");
1127 });
1128 subproc.on("exit", finish);
1129 subproc.stdin.end(name + '\n', "utf8");
1130 }
1131 else
1132 send();
1133 }
1134
1095 var errorcodes = [ "Generic Error", "Not logged in", "Invalid data", 1135 var errorcodes = [ "Generic Error", "Not logged in", "Invalid data",
1096 "Login failed", "Already playing", "Game launch failed", 1136 "Login failed", "Already playing", "Game launch failed",
1097 "Server shutting down", "Game not in progress" ]; 1137 "Server shutting down", "Game not in progress" ];
1098 1138
1099 function sendError(res, ecode, msg, box) { 1139 function sendError(res, ecode, msg, box) {
1110 else 1150 else
1111 res.write(JSON.stringify(edict)); 1151 res.write(JSON.stringify(edict));
1112 res.end(); 1152 res.end();
1113 } 1153 }
1114 1154
1115 // TODO new-objects done to here
1116 function webHandler(req, res) { 1155 function webHandler(req, res) {
1117 /* default headers for the response */ 1156 /* default headers for the response */
1118 var resheaders = {'Content-Type': 'text/html'}; 1157 var resheaders = {'Content-Type': 'text/html'};
1119 /* The request body will be added to this as it arrives. */ 1158 /* The request body will be added to this as it arrives. */
1120 var reqbody = ""; 1159 var reqbody = "";
1190 return; 1229 return;
1191 } 1230 }
1192 else if (target == '/status') { 1231 else if (target == '/status') {
1193 statusmsg(req, res); 1232 statusmsg(req, res);
1194 } 1233 }
1234 else if (target == '/uinfo') {
1235 getuinfo(req, res);
1236 }
1195 else if (target.match(/^\/pstatus\//)) { 1237 else if (target.match(/^\/pstatus\//)) {
1196 pstatusmsg(req, res); 1238 pstatusmsg(req, res);
1197 } 1239 }
1198 else /* Go look for it in the filesystem */ 1240 else /* Go look for it in the filesystem */
1199 serveStatic(req, res, target); 1241 serveStatic(req, res, target);