Skip to content

Commit

Permalink
Merge branch 'bug/rate_limit_#24'
Browse files Browse the repository at this point in the history
Fixes #24
  • Loading branch information
cleverbeagle committed Jul 31, 2017
2 parents 6bfe6a3 + 031f367 commit 7e31166
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
5 changes: 3 additions & 2 deletions imports/api/Users/server/edit-profile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* eslint-disable consistent-return */

import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';

let action;

const updatePassword = (userId, newPassword) => {
try {
throw new Meteor.Error('500', 'Testing failures.');
Accounts.setPassword(userId, newPassword, { logout: false });
} catch (exception) {
action.reject(`[editProfile.updatePassword] ${exception}`);
Expand All @@ -31,13 +33,12 @@ const editProfile = ({ userId, profile }, promise) => {

updateUser(userId, profile);
if (profile.password) updatePassword(userId, profile.password);

action.resolve();
} catch (exception) {
action.reject(`[editProfile.handler] ${exception}`);
}
};


export default options =>
new Promise((resolve, reject) =>
editProfile(options, { resolve, reject }));
11 changes: 2 additions & 9 deletions imports/modules/rate-limit.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
import { _ } from 'meteor/underscore';

const fetchMethodNames = methods => _.pluck(methods, 'name');

const assignLimits = ({ methods, limit, timeRange }) => {
const methodNames = fetchMethodNames(methods);

export default ({ methods, limit, timeRange }) => {
if (Meteor.isServer) {
DDPRateLimiter.addRule({
name(name) { return _.contains(methodNames, name); },
name(name) { return methods.indexOf(name) > -1; },
connectionId() { return true; },
}, limit, timeRange);
}
};

export default function rateLimit(options) { return assignLimits(options); }

0 comments on commit 7e31166

Please sign in to comment.