Fix ActionLog calls for api

This commit is contained in:
calzoneman 2013-08-16 13:25:36 -05:00
parent 3f26fc80e0
commit 063b179ab3
1 changed files with 56 additions and 39 deletions

33
api.js
View File

@ -185,14 +185,23 @@ module.exports = function (Server) {
var ip = getIP(req); var ip = getIP(req);
// Limit registrations per IP within a certain time period // Limit registrations per IP within a certain time period
if(ActionLog.tooManyRegistrations(ip)) { ActionLog.throttleRegistrations(ip, function (err, toomany) {
if(err) {
res.jsonp({
success: false,
error: err
});
return;
}
if(toomany) {
ActionLog.record(ip, name, "register-failure", ActionLog.record(ip, name, "register-failure",
"Too many recent registrations"); "Too many recent registrations");
res.jsonp({ res.jsonp({
success: false, success: false,
error: "Your IP address has registered too many accounts "+ error: "Your IP address has registered too many " +
"in the past 48 hours. Please wait a while before"+ "accounts in the past 48 hours. Please wait " +
" registering another." "a while before registering another."
}); });
return; return;
} }
@ -208,12 +217,13 @@ module.exports = function (Server) {
if(!$util.isValidUserName(name)) { if(!$util.isValidUserName(name)) {
ActionLog.record(ip, name, "register-failure", "Invalid name"); ActionLog.record(ip, name, "register-failure",
"Invalid name");
res.jsonp({ res.jsonp({
success: false, success: false,
error: "Invalid username. Valid usernames must be 1-20 "+ error: "Invalid username. Valid usernames must be " +
"characters long and consist only of alphanumeric "+ "1-20 characters long and consist only of " +
"characters and underscores (_)" "alphanumeric characters and underscores (_)"
}); });
return; return;
} }
@ -235,6 +245,7 @@ module.exports = function (Server) {
}); });
}); });
}); });
});
/* password change */ /* password change */
app.post("/api/account/passwordchange", function (req, res) { app.post("/api/account/passwordchange", function (req, res) {
@ -549,6 +560,12 @@ module.exports = function (Server) {
} }
types = types.split(","); types = types.split(",");
ActionLog.listActions(types, function (err, actions) {
if(err)
actions = [];
res.jsonp(actions);
});
var actions = ActionLog.readLog(types); var actions = ActionLog.readLog(types);
res.jsonp(actions); res.jsonp(actions);
}); });