style changes

v1.18.x
Barış Soner Uşaklı 8 years ago
parent 8db193ff55
commit f6ac92111b

@ -36,9 +36,7 @@ rewards.checkConditionAndRewardUser = function (uid, condition, method, callback
return next(null, false);
}
checkCondition(reward, method, function (result) {
next(null, result);
});
checkCondition(reward, method, next);
}, function (err, eligible) {
if (err || !eligible) {
return next(false);
@ -59,11 +57,11 @@ function getIDsByCondition(condition, callback) {
}
function filterCompletedRewards(uid, rewards, callback) {
db.getSortedSetRangeByScoreWithScores('uid:' + uid + ':rewards', 0, -1, 1, '+inf', function (err, data) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
db.getSortedSetRangeByScoreWithScores('uid:' + uid + ':rewards', 0, -1, 1, '+inf', next);
},
function (data, next) {
var userRewards = {};
data.forEach(function (obj) {
@ -80,8 +78,9 @@ function filterCompletedRewards(uid, rewards, callback) {
return claimable === 0 || (userRewards[reward.id] < reward.claimable);
});
callback(null, rewards);
});
next(null, rewards);
},
], callback);
}
function getRewardDataByIDs(ids, callback) {
@ -97,26 +96,29 @@ function getRewardsByRewardData(rewards, callback) {
}
function checkCondition(reward, method, callback) {
method(function (err, value) {
if (err) {
return callback(err);
}
plugins.fireHook('filter:rewards.checkConditional:' + reward.conditional, { left: value, right: reward.value }, function (err, bool) {
callback(err || bool);
});
});
async.waterfall([
function (next) {
method(next);
},
function (value, next) {
plugins.fireHook('filter:rewards.checkConditional:' + reward.conditional, { left: value, right: reward.value }, next);
},
function (bool, next) {
next(null, bool);
},
], callback);
}
function giveRewards(uid, rewards, callback) {
getRewardsByRewardData(rewards, function (err, rewardData) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
getRewardsByRewardData(rewards, next);
},
function (rewardData, next) {
async.each(rewards, function (reward, next) {
plugins.fireHook('action:rewards.award:' + reward.rid, { uid: uid, reward: rewardData[rewards.indexOf(reward)] });
db.sortedSetIncrBy('uid:' + uid + ':rewards', 1, reward.id, next);
}, callback);
});
}, next);
},
], callback);
}

@ -1,6 +1,6 @@
'use strict';
(function (Auth) {
var async = require('async');
var passport = require('passport');
var passportLocal = require('passport-local').Strategy;
var nconf = require('nconf');
@ -13,6 +13,8 @@
var loginStrategies = [];
var Auth = module.exports;
Auth.initialize = function (app, middleware) {
app.use(passport.initialize());
app.use(passport.session());
@ -43,12 +45,11 @@
passport.use(new passportLocal({ passReqToCallback: true }, controllers.authentication.localLogin));
}
plugins.fireHook('filter:auth.init', loginStrategies, function (err) {
if (err) {
winston.error('filter:auth.init - plugin failure');
return callback(err);
}
async.waterfall([
function (next) {
plugins.fireHook('filter:auth.init', loginStrategies, next);
},
function (loginStrategies, next) {
loginStrategies.forEach(function (strategy) {
if (strategy.url) {
router.get(strategy.url, passport.authenticate(strategy.name, {
@ -70,10 +71,9 @@
router.post('/logout', Auth.middleware.applyCSRF, controllers.authentication.logout);
hotswap.replace('auth', router);
if (typeof callback === 'function') {
callback();
}
});
next();
},
], callback);
};
passport.serializeUser(function (user, done) {
@ -85,4 +85,3 @@
uid: uid,
});
});
}(exports));

@ -205,11 +205,11 @@ module.exports = function (app, middleware, hotswapIds, callback) {
async.apply(plugins.reloadRoutes),
async.apply(authRoutes.reloadRoutes),
async.apply(user.addInterstitials),
], function (err) {
if (err) {
return callback(err);
}
function (next) {
winston.info('Routes added');
callback();
next();
},
], function (err) {
callback(err);
});
};

@ -38,13 +38,18 @@ var SocketAdmin = {
};
SocketAdmin.before = function (socket, method, data, next) {
user.isAdministrator(socket.uid, function (err, isAdmin) {
if (err || isAdmin) {
return next(err);
async.waterfall([
function (next) {
user.isAdministrator(socket.uid, next);
},
function (isAdmin) {
if (isAdmin) {
return next();
}
winston.warn('[socket.io] Call to admin method ( ' + method + ' ) blocked (accessed by uid ' + socket.uid + ')');
next(new Error('[[error:no-privileges]]'));
});
},
], next);
};
SocketAdmin.reload = function (socket, data, callback) {
@ -58,11 +63,11 @@ SocketAdmin.reload = function (socket, data, callback) {
};
SocketAdmin.restart = function (socket, data, callback) {
require('../meta/build').buildAll(function (err) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
require('../meta/build').buildAll(next);
},
function (next) {
events.log({
type: 'build',
uid: socket.uid,
@ -76,8 +81,9 @@ SocketAdmin.restart = function (socket, data, callback) {
});
meta.restart();
callback();
});
next();
},
], callback);
};
SocketAdmin.fireEvent = function (socket, data, callback) {

@ -30,13 +30,7 @@ Categories.getAll = function (socket, data, callback) {
function (result, next) {
next(null, categories.getTree(result.categories, 0));
},
], function (err, categoriesTree) {
if (err) {
return callback(err);
}
callback(null, categoriesTree);
});
], callback);
};
Categories.getNames = function (socket, data, callback) {
@ -93,27 +87,31 @@ Categories.getPrivilegeSettings = function (socket, cid, callback) {
};
Categories.copyPrivilegesToChildren = function (socket, cid, callback) {
categories.getCategories([cid], socket.uid, function (err, categories) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
categories.getCategories([cid], socket.uid, next);
},
function (categories, next) {
var category = categories[0];
async.eachSeries(category.children, function (child, next) {
copyPrivilegesToChildrenRecursive(cid, child, next);
}, callback);
});
}, next);
},
], callback);
};
function copyPrivilegesToChildrenRecursive(parentCid, category, callback) {
categories.copyPrivilegesFrom(parentCid, category.cid, function (err) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
categories.copyPrivilegesFrom(parentCid, category.cid, next);
},
function (next) {
async.eachSeries(category.children, function (child, next) {
copyPrivilegesToChildrenRecursive(parentCid, child, next);
}, callback);
});
}, next);
},
], callback);
}
Categories.copySettingsFrom = function (socket, data, callback) {

@ -3,7 +3,7 @@
var async = require('async');
var groups = require('../../groups');
var Groups = {};
var Groups = module.exports;
Groups.create = function (socket, data, callback) {
if (!data) {
@ -66,5 +66,3 @@ Groups.update = function (socket, data, callback) {
groups.update(data.groupName, data.values, callback);
};
module.exports = Groups;

@ -1,10 +1,8 @@
'use strict';
var navigationAdmin = require('../../navigation/admin');
var SocketNavigation = {};
var SocketNavigation = module.exports;
SocketNavigation.save = function (socket, data, callback) {
navigationAdmin.save(data, callback);
};
module.exports = SocketNavigation;

@ -11,11 +11,11 @@ var pubsub = require('../../pubsub');
var stats = {};
var totals = {};
var SocketRooms = {
stats: stats,
totals: totals,
};
var SocketRooms = module.exports;
SocketRooms.stats = stats;
SocketRooms.totals = totals;
pubsub.on('sync:stats:start', function () {
SocketRooms.getLocalStats(function (err, stats) {
@ -181,6 +181,3 @@ SocketRooms.getLocalStats = function (callback) {
callback(null, socketData);
};
module.exports = SocketRooms;

@ -10,18 +10,18 @@ var events = require('../../events');
var meta = require('../../meta');
var plugins = require('../../plugins');
var User = {};
var User = module.exports;
User.makeAdmins = function (socket, uids, callback) {
if (!Array.isArray(uids)) {
return callback(new Error('[[error:invalid-data]]'));
}
user.getUsersFields(uids, ['banned'], function (err, userData) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
user.getUsersFields(uids, ['banned'], next);
},
function (userData, next) {
for (var i = 0; i < userData.length; i += 1) {
if (userData[i] && parseInt(userData[i].banned, 10) === 1) {
return callback(new Error('[[error:cant-make-banned-users-admin]]'));
@ -30,8 +30,9 @@ User.makeAdmins = function (socket, uids, callback) {
async.each(uids, function (uid, next) {
groups.join('administrators', uid, next);
}, callback);
});
}, next);
},
], callback);
};
User.removeAdmins = function (socket, uids, callback) {
@ -40,17 +41,18 @@ User.removeAdmins = function (socket, uids, callback) {
}
async.eachSeries(uids, function (uid, next) {
groups.getMemberCount('administrators', function (err, count) {
if (err) {
return next(err);
}
async.waterfall([
function (next) {
groups.getMemberCount('administrators', next);
},
function (count, next) {
if (count === 1) {
return next(new Error('[[error:cant-remove-last-admin]]'));
}
groups.leave('administrators', uid, next);
});
},
], next);
}, callback);
};
@ -78,14 +80,16 @@ User.validateEmail = function (socket, uids, callback) {
return parseInt(uid, 10);
});
async.waterfall([
function (next) {
async.each(uids, function (uid, next) {
user.setUserField(uid, 'email:confirmed', 1, next);
}, function (err) {
if (err) {
return callback(err);
}
db.sortedSetRemove('users:notvalidated', uids, callback);
});
}, next);
},
function (next) {
db.sortedSetRemove('users:notvalidated', uids, next);
},
], callback);
};
User.sendValidationEmail = function (socket, uids, callback) {
@ -123,15 +127,17 @@ User.sendPasswordResetEmail = function (socket, uids, callback) {
});
async.each(uids, function (uid, next) {
user.getUserFields(uid, ['email', 'username'], function (err, userData) {
if (err) {
return next(err);
}
async.waterfall([
function (next) {
user.getUserFields(uid, ['email', 'username'], next);
},
function (userData, next) {
if (!userData.email) {
return next(new Error('[[error:user-doesnt-have-email, ' + userData.username + ']]'));
}
user.reset.send(userData.email, next);
});
},
], next);
}, callback);
};
@ -257,5 +263,3 @@ User.rejectRegistration = function (socket, data, callback) {
User.restartJobs = function (socket, data, callback) {
user.startJobs(callback);
};
module.exports = User;

@ -1,24 +1,28 @@
'use strict';
var async = require('async');
var user = require('../user');
var meta = require('../meta');
var SocketBlacklist = {};
var SocketBlacklist = module.exports;
SocketBlacklist.validate = function (socket, data, callback) {
meta.blacklist.validate(data.rules, callback);
};
SocketBlacklist.save = function (socket, rules, callback) {
user.isAdminOrGlobalMod(socket.uid, function (err, isAdminOrGlobalMod) {
if (err || !isAdminOrGlobalMod) {
return callback(err || new Error('[[error:no-privileges]]'));
async.waterfall([
function (next) {
user.isAdminOrGlobalMod(socket.uid, next);
},
function (isAdminOrGlobalMod, next) {
if (!isAdminOrGlobalMod) {
return callback(new Error('[[error:no-privileges]]'));
}
meta.blacklist.save(rules, callback);
});
meta.blacklist.save(rules, next);
},
], callback);
};
module.exports = SocketBlacklist;

@ -8,13 +8,15 @@ var user = require('../user');
var topics = require('../topics');
var apiController = require('../controllers/api');
var SocketCategories = {};
var SocketCategories = module.exports;
SocketCategories.getRecentReplies = function (socket, cid, callback) {
categories.getRecentReplies(cid, socket.uid, 4, callback);
};
SocketCategories.get = function (socket, data, callback) {
async.waterfall([
function (next) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, socket.uid),
categories: function (next) {
@ -23,40 +25,43 @@ SocketCategories.get = function (socket, data, callback) {
async.apply(categories.getCategoriesData),
], next);
},
}, function (err, results) {
if (err) {
return callback(err);
}
}, next);
},
function (results, next) {
results.categories = results.categories.filter(function (category) {
return category && (!category.disabled || results.isAdmin);
});
callback(null, results.categories);
});
next(null, results.categories);
},
], callback);
};
SocketCategories.getWatchedCategories = function (socket, data, callback) {
async.waterfall([
function (next) {
async.parallel({
categories: async.apply(categories.getCategoriesByPrivilege, 'cid:0:children', socket.uid, 'find'),
ignoredCids: async.apply(user.getIgnoredCategories, socket.uid),
}, function (err, results) {
if (err) {
return callback(err);
}
}, next);
},
function (results, next) {
var watchedCategories = results.categories.filter(function (category) {
return category && results.ignoredCids.indexOf(category.cid.toString()) === -1;
});
callback(null, watchedCategories);
});
next(null, watchedCategories);
},
], callback);
};
SocketCategories.loadMore = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
var userPrivileges;
async.waterfall([
function (next) {
async.parallel({
privileges: function (next) {
privileges.categories.get(data.cid, socket.uid, next);
@ -71,15 +76,13 @@ SocketCategories.loadMore = function (socket, data, callback) {
next();
}
},
}, function (err, results) {
if (err) {
return callback(err);
}
if (!results.privileges.read) {
}, next);
},
function (results, next) {
userPrivileges = results.privileges;
if (!userPrivileges.read) {
return callback(new Error('[[error:no-privileges]]'));
}
var infScrollTopicsPerPage = 20;
var set = 'cid:' + data.cid + ':tids';
var reverse = false;
@ -119,22 +122,20 @@ SocketCategories.loadMore = function (socket, data, callback) {
uid: socket.uid,
targetUid: results.targetUid,
settings: results.settings,
}, function (err, data) {
if (err) {
return callback(err);
}
categories.modifyTopicsByPrivilege(data.topics, results.privileges);
}, next);
},
function (data, next) {
categories.modifyTopicsByPrivilege(data.topics, userPrivileges);
data.privileges = results.privileges;
data.privileges = userPrivileges;
data.template = {
category: true,
name: 'category',
};
callback(null, data);
});
});
next(null, data);
},
], callback);
};
SocketCategories.getPageCount = function (socket, cid, callback) {
@ -150,6 +151,8 @@ SocketCategories.getCategoriesByPrivilege = function (socket, privilege, callbac
};
SocketCategories.getMoveCategories = function (socket, data, callback) {
async.waterfall([
function (next) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, socket.uid),
categories: function (next) {
@ -165,17 +168,16 @@ SocketCategories.getMoveCategories = function (socket, data, callback) {
},
], next);
},
}, function (err, results) {
if (err) {
return callback(err);
}
}, next);
},
function (results, next) {
results.categories = results.categories.filter(function (category) {
return category && (!category.disabled || results.isAdmin) && !category.link;
});
callback(null, results.categories);
});
next(null, results.categories);
},
], callback);
};
SocketCategories.watch = function (socket, cid, callback) {
@ -231,5 +233,3 @@ SocketCategories.isModerator = function (socket, cid, callback) {
SocketCategories.getCategory = function (socket, cid, callback) {
apiController.getCategoryData(cid, socket.uid, callback);
};
module.exports = SocketCategories;

@ -26,14 +26,11 @@ SocketFlags.create = function (socket, data, callback) {
// If we got here, then no errors occurred
flags.create(data.type, data.id, socket.uid, data.reason, next);
},
], function (err, flagObj) {
if (err) {
return callback(err);
}
function (flagObj, next) {
flags.notify(flagObj, socket.uid);
callback(null, flagObj);
});
next(null, flagObj);
},
], callback);
};
SocketFlags.update = function (socket, data, callback) {

@ -8,8 +8,7 @@ var user = require('../user');
var utils = require('../utils');
var groupsController = require('../controllers/groups');
var SocketGroups = {};
var SocketGroups = module.exports;
SocketGroups.before = function (socket, method, data, next) {
if (!data) {
@ -304,5 +303,3 @@ SocketGroups.cover.remove = function (socket, data, callback) {
},
], callback);
};
module.exports = SocketGroups;

@ -13,7 +13,7 @@ var utils = require('../utils');
var apiController = require('../controllers/api');
var SocketPosts = {};
var SocketPosts = module.exports;
require('./posts/edit')(SocketPosts);
require('./posts/move')(SocketPosts);
@ -152,6 +152,3 @@ SocketPosts.getReplies = function (socket, pid, callback) {
},
], callback);
};
module.exports = SocketPosts;

@ -60,9 +60,13 @@ module.exports = function (SocketPosts) {
return callback(new Error('[[error:invalid-data]]'));
}
posts.getUpvotedUidsByPids(pids, function (err, data) {
if (err || !Array.isArray(data) || !data.length) {
return callback(err, []);
async.waterfall([
function (next) {
posts.getUpvotedUidsByPids(pids, next);
},
function (data, next) {
if (!data.length) {
return callback(null, []);
}
async.map(data, function (uids, next) {
@ -77,8 +81,9 @@ module.exports = function (SocketPosts) {
usernames: usernames,
});
});
}, callback);
});
}, next);
},
], callback);
};
SocketPosts.upvote = function (socket, data, callback) {

@ -197,17 +197,18 @@ SocketUser.unfollow = function (socket, data, callback) {
};
function toggleFollow(method, uid, theiruid, callback) {
user[method](uid, theiruid, function (err) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
user[method](uid, theiruid, next);
},
function (next) {
plugins.fireHook('action:user.' + method, {
fromUid: uid,
toUid: theiruid,
});
callback();
});
next();
},
], callback);
}
SocketUser.saveSettings = function (socket, data, callback) {

@ -121,11 +121,11 @@ module.exports = function (SocketUser) {
function (next) {
if (!reason) {
return translator.translate('[[user:info.banned-no-reason]]', function (translated) {
next(false, translated);
next(null, translated);
});
}
next(false, reason);
next(null, reason);
},
function (_reason, next) {
websockets.in('uid_' + uid).emit('event:banned', {

@ -67,6 +67,8 @@ module.exports = function (SocketUser) {
};
function isAdminOrSelfAndPasswordMatch(uid, data, callback) {
async.waterfall([
function (next) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, uid),
hasPassword: async.apply(user.hasPassword, data.uid),
@ -77,22 +79,22 @@ module.exports = function (SocketUser) {
next(null, false);
}
},
}, function (err, results) {
if (err) {
return callback(err);
}
}, next);
},
function (results, next) {
var isSelf = parseInt(uid, 10) === parseInt(data.uid, 10);
if (!results.isAdmin && !isSelf) {
return callback(new Error('[[error:no-privileges]]'));
return next(new Error('[[error:no-privileges]]'));
}
if (isSelf && results.hasPassword && !results.passwordMatch) {
return callback(new Error('[[error:invalid-password]]'));
return next(new Error('[[error:invalid-password]]'));
}
callback();
});
next();
},
], callback);
}
SocketUser.changePassword = function (socket, data, callback) {
@ -103,20 +105,20 @@ module.exports = function (SocketUser) {
if (!data || !data.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
user.changePassword(socket.uid, data, function (err) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
user.changePassword(socket.uid, data, next);
},
function (next) {
events.log({
type: 'password-change',
uid: socket.uid,
targetUid: data.uid,
ip: socket.ip,
});
callback();
});
next();
},
], callback);
};
SocketUser.updateProfile = function (socket, data, callback) {

@ -1,5 +1,7 @@
'use strict';
var async = require('async');
var user = require('../../user');
var meta = require('../../meta');
var pagination = require('../../pagination');
@ -9,9 +11,13 @@ module.exports = function (SocketUser) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
if (!socket.uid && parseInt(meta.config.allowGuestUserSearching, 10) !== 1) {
return callback(new Error('[[error:not-logged-in]]'));
}
async.waterfall([
function (next) {
user.search({
query: data.query,
page: data.page,
@ -21,13 +27,13 @@ module.exports = function (SocketUser) {
bannedOnly: data.bannedOnly,
flaggedOnly: data.flaggedOnly,
uid: socket.uid,
}, function (err, result) {
if (err) {
return callback(err);
}
}, next);
},
function (result, next) {
result.pagination = pagination.create(data.page, result.pageCount);
result['route_users:' + data.sortBy] = true;
callback(null, result);
});
next(null, result);
},
], callback);
};
};

@ -1,5 +1,6 @@
'use strict';
var async = require('async');
var validator = require('validator');
var db = require('../database');
@ -21,27 +22,29 @@ function escapeTitle(topicData) {
module.exports = function (Topics) {
Topics.getTopicField = function (tid, field, callback) {
db.getObjectField('topic:' + tid, field, function (err, value) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
db.getObjectField('topic:' + tid, field, next);
},
function (value, next) {
if (field === 'title') {
value = translator.escape(validator.escape(String(value)));
}
callback(null, value);
});
next(null, value);
},
], callback);
};
Topics.getTopicFields = function (tid, fields, callback) {
db.getObjectFields('topic:' + tid, fields, function (err, topic) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
db.getObjectFields('topic:' + tid, fields, next);
},
function (topic, next) {
escapeTitle(topic);
callback(null, topic);
});
next(null, topic);
},
], callback);
};
Topics.getTopicsFields = function (tids, fields, callback) {
@ -51,42 +54,38 @@ module.exports = function (Topics) {
var keys = tids.map(function (tid) {
return 'topic:' + tid;
});
db.getObjectsFields(keys, fields, function (err, topics) {
if (err) {
return callback(err);
async.waterfall([
function (next) {
if (fields.length) {
db.getObjectsFields(keys, fields, next);
} else {
db.getObjects(keys, next);
}
topics.forEach(escapeTitle);
callback(null, topics);
});
},
function (topics, next) {
topics.forEach(modifyTopic);
next(null, topics);
},
], callback);
};
Topics.getTopicData = function (tid, callback) {
db.getObject('topic:' + tid, function (err, topic) {
if (err || !topic) {
return callback(err);
async.waterfall([
function (next) {
db.getObject('topic:' + tid, next);
},
function (topic, next) {
if (!topic) {
return next(null, null);
}
modifyTopic(topic);
callback(null, topic);
});
next(null, topic);
},
], callback);
};
Topics.getTopicsData = function (tids, callback) {
var keys = [];
for (var i = 0; i < tids.length; i += 1) {
keys.push('topic:' + tids[i]);
}
db.getObjects(keys, function (err, topics) {
if (err) {
return callback(err);
}
topics.forEach(modifyTopic);
callback(null, topics);
});
Topics.getTopicsFields(tids, [], callback);
};
function modifyTopic(topic) {
@ -102,13 +101,14 @@ module.exports = function (Topics) {
}
Topics.getCategoryData = function (tid, callback) {
Topics.getTopicField(tid, 'cid', function (err, cid) {
if (err) {
return callback(err);
}
categories.getCategoryData(cid, callback);
});
async.waterfall([
function (next) {
Topics.getTopicField(tid, 'cid', next);
},
function (cid, next) {
categories.getCategoryData(cid, next);
},
], callback);
};
Topics.setTopicField = function (tid, field, value, callback) {

@ -126,22 +126,23 @@ module.exports = function (Topics) {
async.parallel([
async.apply(updateRecentTopic, tid),
async.apply(updateRecentTopic, postData.tid),
], next);
},
], function (err) {
if (err) {
return callback(err);
}
plugins.fireHook('action:post.move', { post: postData, tid: tid });
callback();
next(err);
});
},
function (next) {
plugins.fireHook('action:post.move', { post: postData, tid: tid });
next();
},
], callback);
};
function updateCategoryPostCount(oldTid, tid, callback) {
Topics.getTopicsFields([oldTid, tid], ['cid'], function (err, topicData) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
Topics.getTopicsFields([oldTid, tid], ['cid'], next);
},
function (topicData, next) {
if (!topicData[0].cid || !topicData[1].cid) {
return callback();
}
@ -151,8 +152,9 @@ module.exports = function (Topics) {
async.parallel([
async.apply(db.incrObjectFieldBy, 'category:' + topicData[0].cid, 'post_count', -1),
async.apply(db.incrObjectFieldBy, 'category:' + topicData[1].cid, 'post_count', 1),
], next);
},
], callback);
});
}
function updateRecentTopic(tid, callback) {

@ -9,6 +9,8 @@ var search = require('../search');
module.exports = function (Topics) {
Topics.getSuggestedTopics = function (tid, uid, start, stop, callback) {
async.waterfall([
function (next) {
async.parallel({
tagTids: function (next) {
getTidsWithSameTags(tid, next);
@ -19,10 +21,9 @@ module.exports = function (Topics) {
categoryTids: function (next) {
getCategoryTids(tid, next);
},
}, function (err, results) {
if (err) {
return callback(err);
}
}, next);
},
function (results, next) {
var tids = results.tagTids.concat(results.searchTids).concat(results.categoryTids);
tids = tids.filter(function (_tid, index, array) {
return parseInt(_tid, 10) !== parseInt(tid, 10) && array.indexOf(_tid) === index;
@ -34,8 +35,9 @@ module.exports = function (Topics) {
tids = tids.slice(start, stop + 1);
}
Topics.getTopics(tids, uid, callback);
});
Topics.getTopics(tids, uid, next);
},
], callback);
};
function getTidsWithSameTags(tid, callback) {

@ -13,7 +13,6 @@ module.exports = function (Topics) {
var topicTools = {};
Topics.tools = topicTools;
topicTools.delete = function (tid, uid, callback) {
toggleDelete(tid, uid, true, callback);
};
@ -246,6 +245,7 @@ module.exports = function (Topics) {
topicTools.move = function (tid, cid, uid, callback) {
var topic;
var oldCid;
async.waterfall([
function (next) {
Topics.exists(tid, next);
@ -276,14 +276,13 @@ module.exports = function (Topics) {
topic.postcount = topic.postcount || 0;
db.sortedSetAdd('cid:' + cid + ':tids:posts', topic.postcount, tid, next);
},
], next);
}
},
], function (err) {
if (err) {
return callback(err);
next(err);
});
}
var oldCid = topic.cid;
},
function (next) {
oldCid = topic.cid;
categories.moveRecentReplies(tid, oldCid, cid);
async.parallel([
@ -300,17 +299,18 @@ module.exports = function (Topics) {
}, next);
},
], function (err) {
if (err) {
return callback(err);
}
next(err);
});
},
function (next) {
plugins.fireHook('action:topic.move', {
tid: tid,
fromCid: oldCid,
toCid: cid,
uid: uid,
});
callback();
});
});
next();
},
], callback);
};
};

@ -326,6 +326,8 @@ module.exports = function (Topics) {
}));
}
async.waterfall([
function (next) {
async.parallel({
recentScores: function (next) {
db.sortedSetScores('topics:recent', tids, next);
@ -336,11 +338,9 @@ module.exports = function (Topics) {
tids_unread: function (next) {
db.sortedSetScores('uid:' + uid + ':tids_unread', tids, next);
},
}, function (err, results) {
if (err) {
return callback(err);
}
}, next);
},
function (results, next) {
var cutoff = Topics.unreadCutoff();
var result = tids.map(function (tid, index) {
return !results.tids_unread[index] &&
@ -348,8 +348,9 @@ module.exports = function (Topics) {
!!(results.userScores[index] && results.userScores[index] >= results.recentScores[index]));
});
callback(null, result);
});
next(null, result);
},
], callback);
};
Topics.hasReadTopic = function (tid, uid, callback) {

@ -11,6 +11,8 @@ module.exports = function (User) {
};
User.getWatchedCategories = function (uid, callback) {
async.waterfall([
function (next) {
async.parallel({
ignored: function (next) {
User.getIgnoredCategories(uid, next);
@ -18,16 +20,15 @@ module.exports = function (User) {
all: function (next) {
db.getSortedSetRange('categories:cid', 0, -1, next);
},
}, function (err, results) {
if (err) {
return callback(err);
}
}, next);
},
function (results, next) {
var watched = results.all.filter(function (cid) {
return cid && results.ignored.indexOf(cid) === -1;
});
callback(null, watched);
});
next(null, watched);
},
], callback);
};
User.ignoreCategory = function (uid, cid, callback) {

@ -15,14 +15,16 @@ module.exports = function (User) {
if (data.email !== undefined) {
data.email = validator.escape(String(data.email).trim());
}
User.isDataValid(data, function (err) {
if (err) {
return callback(err);
}
var timestamp = data.timestamp || Date.now();
var userData;
var userNameChanged = false;
var userData = {
async.waterfall([
function (next) {
User.isDataValid(data, next);
},
function (next) {
userData = {
username: data.username,
userslug: data.userslug,
email: data.email || '',
@ -44,27 +46,19 @@ module.exports = function (User) {
status: 'online',
};
async.parallel({
renamedUsername: function (next) {
User.uniqueUsername(userData, next);
},
userData: function (next) {
plugins.fireHook('filter:user.create', { user: userData, data: data }, next);
},
}, function (err, results) {
if (err) {
return callback(err);
}
var userNameChanged = !!results.renamedUsername;
function (renamedUsername, next) {
userNameChanged = !!renamedUsername;
if (userNameChanged) {
userData.username = results.renamedUsername;
userData.userslug = utils.slugify(results.renamedUsername);
userData.username = renamedUsername;
userData.userslug = utils.slugify(renamedUsername);
}
async.waterfall([
function (next) {
plugins.fireHook('filter:user.create', { user: userData, data: data }, next);
},
function (results, next) {
userData = results.user;
db.incrObjectField('global', 'nextUid', next);
},
function (uid, next) {
@ -144,8 +138,6 @@ module.exports = function (User) {
next(null, userData.uid);
},
], callback);
});
});
};
User.isDataValid = function (userData, callback) {
@ -201,26 +193,23 @@ module.exports = function (User) {
};
User.uniqueUsername = function (userData, callback) {
meta.userOrGroupExists(userData.userslug, function (err, exists) {
if (err || !exists) {
return callback(err);
}
var num = 0;
function go() {
var username = userData.username + ' ' + num.toString(32);
meta.userOrGroupExists(username, function (err, exists) {
if (err || !exists) {
return callback(err, username);
var numTries = 0;
function go(username) {
async.waterfall([
function (next) {
meta.userOrGroupExists(username, next);
},
function (exists) {
if (!exists) {
return callback(null, numTries ? username : null);
}
num += 1;
go();
});
username = userData.username + ' ' + numTries.toString(32);
numTries += 1;
go(username);
},
], callback);
}
go();
});
go(userData.userslug);
};
};

@ -191,7 +191,6 @@ UserNotifications.getUnreadCount = function (uid, callback) {
return callback(null, 0);
}
async.waterfall([
function (next) {
db.getSortedSetRevRange('uid:' + uid + ':notifications:unread', 0, 99, next);

@ -17,22 +17,21 @@ module.exports = function (User) {
User.isPasswordCorrect = function (uid, password, callback) {
password = password || '';
var hashedPassword;
async.waterfall([
function (next) {
db.getObjectField('user:' + uid, 'password', next);
},
function (hashedPassword, next) {
function (_hashedPassword, next) {
hashedPassword = _hashedPassword;
if (!hashedPassword) {
return callback(null, true);
}
User.isPasswordValid(password, function (err) {
if (err) {
return next(err);
}
User.isPasswordValid(password, next);
},
function (next) {
Password.compare(password, hashedPassword, next);
});
},
], callback);
};

@ -183,14 +183,15 @@ module.exports = function (User) {
if (!convertToPNG) {
return setImmediate(callback, null, path);
}
image.normalise(path, extension, function (err, newPath) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
image.normalise(path, extension, next);
},
function (newPath, next) {
file.delete(path);
callback(null, newPath);
});
next(null, newPath);
},
], callback);
}
function uploadProfileOrCover(filename, image, callback) {

@ -10,7 +10,8 @@ module.exports = function (User) {
if (parseInt(uid, 10) === 0) {
return callback();
}
async.waterfall([
function (next) {
async.parallel({
userData: function (next) {
User.getUserFields(uid, ['banned', 'lastposttime', 'joindate', 'email', 'email:confirmed', 'reputation'], next);
@ -21,44 +22,43 @@ module.exports = function (User) {
isAdminOrMod: function (next) {
privileges.categories.isAdminOrMod(cid, uid, next);
},
}, function (err, results) {
if (err) {
return callback(err);
}
}, next);
},
function (results, next) {
if (!results.exists) {
return callback(new Error('[[error:no-user]]'));
return next(new Error('[[error:no-user]]'));
}
if (results.isAdminOrMod) {
return callback();
return next();
}
var userData = results.userData;
if (parseInt(userData.banned, 10) === 1) {
return callback(new Error('[[error:user-banned]]'));
return next(new Error('[[error:user-banned]]'));
}
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
return callback(new Error('[[error:email-not-confirmed]]'));
return next(new Error('[[error:email-not-confirmed]]'));
}
var now = Date.now();
if (now - parseInt(userData.joindate, 10) < parseInt(meta.config.initialPostDelay, 10) * 1000) {
return callback(new Error('[[error:user-too-new, ' + meta.config.initialPostDelay + ']]'));
return next(new Error('[[error:user-too-new, ' + meta.config.initialPostDelay + ']]'));
}
var lastposttime = userData.lastposttime || 0;
if (parseInt(meta.config.newbiePostDelay, 10) > 0 && parseInt(meta.config.newbiePostDelayThreshold, 10) > parseInt(userData.reputation, 10) && now - parseInt(lastposttime, 10) < parseInt(meta.config.newbiePostDelay, 10) * 1000) {
return callback(new Error('[[error:too-many-posts-newbie, ' + meta.config.newbiePostDelay + ', ' + meta.config.newbiePostDelayThreshold + ']]'));
return next(new Error('[[error:too-many-posts-newbie, ' + meta.config.newbiePostDelay + ', ' + meta.config.newbiePostDelayThreshold + ']]'));
} else if (now - parseInt(lastposttime, 10) < parseInt(meta.config.postDelay, 10) * 1000) {
return callback(new Error('[[error:too-many-posts, ' + meta.config.postDelay + ']]'));
return next(new Error('[[error:too-many-posts, ' + meta.config.postDelay + ']]'));
}
callback();
});
next();
},
], callback);
};
User.onNewPostMade = function (postData, callback) {
@ -84,15 +84,17 @@ module.exports = function (User) {
User.incrementUserPostCountBy = function (uid, value, callback) {
callback = callback || function () {};
User.incrementUserFieldBy(uid, 'postcount', value, function (err, newpostcount) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
User.incrementUserFieldBy(uid, 'postcount', value, next);
},
function (newpostcount, next) {
if (!parseInt(uid, 10)) {
return callback();
return next();
}
db.sortedSetAdd('users:postcount', newpostcount, uid, callback);
});
db.sortedSetAdd('users:postcount', newpostcount, uid, next);
},
], callback);
};
User.getPostIds = function (uid, start, stop, callback) {

@ -63,9 +63,9 @@ module.exports.listen = function (callback) {
helpers.register();
logger.init(app);
next();
initializeNodeBB(next);
},
initializeNodeBB,
function (next) {
winston.info('NodeBB Ready');

@ -69,6 +69,31 @@ describe('User', function () {
done();
});
});
it('should error with invalid password', function (done) {
User.create({ username: 'test', password: '1' }, function (err) {
assert.equal(err.message, '[[user:change_password_error_length]]');
done();
});
});
it('should error with invalid password', function (done) {
User.create({ username: 'test', password: {} }, function (err) {
assert.equal(err.message, '[[error:invalid-password]]');
done();
});
});
it('should error with a too long password', function (done) {
var toolong = '';
for (var i = 0; i < 5000; i++) {
toolong += 'a';
}
User.create({ username: 'test', password: toolong }, function (err) {
assert.equal(err.message, '[[error:password-too-long]]');
done();
});
});
});
describe('.uniqueUsername()', function () {
@ -77,7 +102,6 @@ describe('User', function () {
for (var i = 0; i < 10; i += 1) {
users.push({
username: 'Jane Doe',
password: 'abcdefghi',
email: 'jane.doe' + i + '@example.com',
});
}

Loading…
Cancel
Save