Fix ActionLog calls for api

This commit is contained in:
calzoneman 2013-08-16 13:25:36 -05:00
parent 3f26fc80e0
commit 063b179ab3

33
api.js
View file

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