do not do rate limit checks for admin, and use createdAt instead of submitted

This commit is contained in:
Sacha Greif 2013-01-13 19:18:01 +09:00
parent f7fff10572
commit 63abe81d2c
2 changed files with 11 additions and 8 deletions

View file

@ -32,12 +32,15 @@ Meteor.methods({
throw new Meteor.Error(603, 'This link has already been posted', postWithSameLink._id);
}
// check that user waits more than 30 seconds between posts
if(!this.isSimulation && timeSinceLastPost < postInterval)
throw new Meteor.Error(604, 'Please wait '+(postInterval-timeSinceLastPost)+' seconds before posting again');
if(!isAdmin(Meteor.user())){
// check that user waits more than X seconds between posts
if(!this.isSimulation && timeSinceLastPost < postInterval)
throw new Meteor.Error(604, 'Please wait '+(postInterval-timeSinceLastPost)+' seconds before posting again');
if(!this.isSimulation && numberOfPostsInPast24Hours > maxPostsPer24Hours)
throw new Meteor.Error(605, 'Sorry, you cannot submit more than '+maxPostsPer24Hours+' posts per day');
// check that the user doesn't post more than Y posts per day
if(!this.isSimulation && numberOfPostsInPast24Hours > maxPostsPer24Hours)
throw new Meteor.Error(605, 'Sorry, you cannot submit more than '+maxPostsPer24Hours+' posts per day');
}
post = _.extend(post, {
headline: headline,

View file

@ -49,20 +49,20 @@ userProfileComplete = function(user) {
}
findLast = function(user, collection){
return collection.findOne({userId: user._id}, {sort: {submitted: -1}});
return collection.findOne({userId: user._id}, {sort: {createdAt: -1}});
}
timeSinceLast = function(user, collection){
var now = new Date().getTime();
var last = findLast(user, collection);
if(!last)
return 999; // if this is the user's first post or comment ever, stop here
return Math.abs(Math.floor((now-last.submitted)/1000));
return Math.abs(Math.floor((now-last.createdAt)/1000));
}
numberOfItemsInPast24Hours = function(user, collection){
var mDate = moment(new Date());
var items=collection.find({
userId: user._id,
submitted: {
createdAt: {
$gte: mDate.subtract('hours',24).valueOf()
}
});