Mercurial > hg > rlgwebd
comparison rlgwebd.js @ 126:3e3824711791
RLG-Web server: allow changing e-mail and password.
Logged-in users can change their e-mail addresses and passwords with a
POST to the /uinfo interface.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Sun, 26 Aug 2012 19:04:57 -0700 |
parents | 5ad15380f851 |
children | 823e878e5840 |
comparison
equal
deleted
inserted
replaced
125:5ad15380f851 | 126:3e3824711791 |
---|---|
1135 send404(res, urlobj.pathname, req.method == 'HEAD'); | 1135 send404(res, urlobj.pathname, req.method == 'HEAD'); |
1136 return; | 1136 return; |
1137 } | 1137 } |
1138 } | 1138 } |
1139 | 1139 |
1140 function setuinfo(req, res, postdata) { | |
1141 var urlobj = url.parse(req.url, true); | |
1142 var query = urlobj.query; | |
1143 if (!("key" in query) || !(query["key"] in logins)) { | |
1144 sendError(res, 1); | |
1145 return; | |
1146 } | |
1147 var name = logins[query["key"]].name; | |
1148 var match = urlobj.pathname.match(/^\/[^\/]*\/(.*)/); | |
1149 if (!match || !match[1]) { | |
1150 send404(res, urlobj.pathname, true); | |
1151 return; | |
1152 } | |
1153 var which = match[1]; | |
1154 if (!("v" in postdata)) { | |
1155 sendError(res, 2, "No value provided"); | |
1156 return; | |
1157 } | |
1158 if (which == "email" || which == "pw") { | |
1159 var args; | |
1160 if (which == "email") | |
1161 args = ["setmail"]; | |
1162 else | |
1163 args = ["setpw"]; | |
1164 var child = child_process.execFile("/bin/sqlickrypt", args, | |
1165 function (err, stdout, stderr) { | |
1166 if (err) { | |
1167 tslog("Could not set %s: sqlickrypt error %d", which, err.code); | |
1168 sendError(res, 2); | |
1169 } | |
1170 else { | |
1171 tslog("User %s has changed %s", name, which); | |
1172 res.writeHead(200, { "Content-Type": "application/json" }); | |
1173 res.end(JSON.stringify({"t": "t"})); | |
1174 } | |
1175 }); | |
1176 child.stdin.end(name + "\n" + postdata.v + "\n", "utf8"); | |
1177 } | |
1178 else { | |
1179 send404(res, urlobj.pathname, true); | |
1180 } | |
1181 } | |
1182 | |
1140 var errorcodes = [ "Generic Error", "Not logged in", "Invalid data", | 1183 var errorcodes = [ "Generic Error", "Not logged in", "Invalid data", |
1141 "Login failed", "Already playing", "Game launch failed", | 1184 "Login failed", "Already playing", "Game launch failed", |
1142 "Server shutting down", "Game not in progress" ]; | 1185 "Server shutting down", "Game not in progress" ]; |
1143 | 1186 |
1144 function sendError(res, ecode, msg, box) { | 1187 function sendError(res, ecode, msg, box) { |
1225 watch(req, res, formdata); | 1268 watch(req, res, formdata); |
1226 } | 1269 } |
1227 else if (target == "/quit") { | 1270 else if (target == "/quit") { |
1228 stopgame(res, formdata); | 1271 stopgame(res, formdata); |
1229 } | 1272 } |
1273 else if (target.match(/^\/uinfo\//)) { | |
1274 setuinfo(req, res, formdata); | |
1275 } | |
1230 else { | 1276 else { |
1231 res.writeHead(405, resheaders); | 1277 res.writeHead(405, resheaders); |
1232 res.end(); | 1278 res.end(); |
1233 } | 1279 } |
1234 } | 1280 } |