Merge remote-tracking branch 'origin/master' into develop

This commit is contained in:
Julian Lam
2017-03-15 10:01:00 -04:00
24 changed files with 279 additions and 214 deletions

View File

@@ -82,7 +82,7 @@ module.exports = function (middleware) {
picture: meta.config.defaultAvatar,
status: 'offline',
reputation: 0,
'email:confirmed': false,
'email:confirmed': 0,
};
if (req.uid) {
user.getUserFields(req.uid, Object.keys(userData), next);

View File

@@ -11,85 +11,90 @@ var batch = require('../batch');
module.exports = function (Topics) {
Topics.delete = function (tid, uid, callback) {
Topics.getTopicFields(tid, ['cid'], function (err, topicData) {
if (err) {
return callback(err);
}
async.parallel([
function (next) {
Topics.setTopicFields(tid, {
deleted: 1,
deleterUid: uid,
deletedTimestamp: Date.now(),
}, next);
},
function (next) {
db.sortedSetsRemove(['topics:recent', 'topics:posts', 'topics:views'], tid, next);
},
function (next) {
Topics.getPids(tid, function (err, pids) {
if (err) {
return next(err);
}
db.sortedSetRemove('cid:' + topicData.cid + ':pids', pids, next);
});
},
], function (err) {
callback(err);
});
async.parallel([
function (next) {
Topics.setTopicFields(tid, {
deleted: 1,
deleterUid: uid,
deletedTimestamp: Date.now(),
}, next);
},
function (next) {
db.sortedSetsRemove(['topics:recent', 'topics:posts', 'topics:views'], tid, next);
},
function (next) {
async.waterfall([
function (next) {
async.parallel({
cid: function (next) {
Topics.getTopicField(tid, 'cid', next);
},
pids: function (next) {
Topics.getPids(tid, next);
},
}, next);
},
function (results, next) {
db.sortedSetRemove('cid:' + results.cid + ':pids', results.pids, next);
},
], next);
},
], function (err) {
callback(err);
});
};
Topics.restore = function (tid, uid, callback) {
Topics.getTopicFields(tid, ['cid', 'lastposttime', 'postcount', 'viewcount'], function (err, topicData) {
if (err) {
return callback(err);
}
async.parallel([
function (next) {
Topics.setTopicField(tid, 'deleted', 0, next);
},
function (next) {
Topics.deleteTopicFields(tid, ['deleterUid', 'deletedTimestamp'], next);
},
function (next) {
Topics.updateRecent(tid, topicData.lastposttime, next);
},
function (next) {
db.sortedSetAdd('topics:posts', topicData.postcount, tid, next);
},
function (next) {
db.sortedSetAdd('topics:views', topicData.viewcount, tid, next);
},
function (next) {
Topics.getPids(tid, function (err, pids) {
if (err) {
return callback(err);
}
posts.getPostsFields(pids, ['pid', 'timestamp', 'deleted'], function (err, postData) {
if (err) {
return next(err);
}
postData = postData.filter(function (post) {
return post && parseInt(post.deleted, 10) !== 1;
});
var pidsToAdd = [];
var scores = [];
postData.forEach(function (post) {
pidsToAdd.push(post.pid);
scores.push(post.timestamp);
});
db.sortedSetAdd('cid:' + topicData.cid + ':pids', scores, pidsToAdd, next);
});
});
},
], function (err) {
callback(err);
});
});
var topicData;
async.waterfall([
function (next) {
Topics.getTopicFields(tid, ['cid', 'lastposttime', 'postcount', 'viewcount'], next);
},
function (_topicData, next) {
topicData = _topicData;
async.parallel([
function (next) {
Topics.setTopicField(tid, 'deleted', 0, next);
},
function (next) {
Topics.deleteTopicFields(tid, ['deleterUid', 'deletedTimestamp'], next);
},
function (next) {
Topics.updateRecent(tid, topicData.lastposttime, next);
},
function (next) {
db.sortedSetAdd('topics:posts', topicData.postcount, tid, next);
},
function (next) {
db.sortedSetAdd('topics:views', topicData.viewcount, tid, next);
},
function (next) {
async.waterfall([
function (next) {
Topics.getPids(tid, next);
},
function (pids, next) {
posts.getPostsFields(pids, ['pid', 'timestamp', 'deleted'], next);
},
function (postData, next) {
postData = postData.filter(function (post) {
return post && parseInt(post.deleted, 10) !== 1;
});
var pidsToAdd = [];
var scores = [];
postData.forEach(function (post) {
pidsToAdd.push(post.pid);
scores.push(post.timestamp);
});
db.sortedSetAdd('cid:' + topicData.cid + ':pids', scores, pidsToAdd, next);
},
], next);
},
], function (err) {
next(err);
});
},
], callback);
};
Topics.purgePostsAndTopic = function (tid, uid, callback) {
@@ -179,24 +184,28 @@ module.exports = function (Topics) {
}
function deleteTopicFromCategoryAndUser(tid, callback) {
Topics.getTopicFields(tid, ['cid', 'uid'], function (err, topicData) {
if (err) {
return callback(err);
}
async.parallel([
function (next) {
db.sortedSetsRemove([
'cid:' + topicData.cid + ':tids',
'cid:' + topicData.cid + ':tids:pinned',
'cid:' + topicData.cid + ':tids:posts',
'cid:' + topicData.cid + ':uid:' + topicData.uid + ':tids',
'uid:' + topicData.uid + ':topics',
], tid, next);
},
function (next) {
user.decrementUserFieldBy(topicData.uid, 'topiccount', 1, next);
},
], callback);
async.waterfall([
function (next) {
Topics.getTopicFields(tid, ['cid', 'uid'], next);
},
function (topicData, next) {
async.parallel([
function (next) {
db.sortedSetsRemove([
'cid:' + topicData.cid + ':tids',
'cid:' + topicData.cid + ':tids:pinned',
'cid:' + topicData.cid + ':tids:posts',
'cid:' + topicData.cid + ':uid:' + topicData.uid + ':tids',
'uid:' + topicData.uid + ':topics',
], tid, next);
},
function (next) {
user.decrementUserFieldBy(topicData.uid, 'topiccount', 1, next);
},
], next);
},
], function (err) {
callback(err);
});
}
@@ -207,26 +216,28 @@ module.exports = function (Topics) {
db.incrObjectFieldBy('global', 'topicCount', incr, next);
},
function (next) {
Topics.getTopicFields(tid, ['cid', 'postcount'], function (err, topicData) {
if (err) {
return next(err);
}
topicData.postcount = parseInt(topicData.postcount, 10);
topicData.postcount = topicData.postcount || 0;
var postCountChange = incr * topicData.postcount;
async.waterfall([
function (next) {
Topics.getTopicFields(tid, ['cid', 'postcount'], next);
},
function (topicData, next) {
topicData.postcount = parseInt(topicData.postcount, 10);
topicData.postcount = topicData.postcount || 0;
var postCountChange = incr * topicData.postcount;
async.parallel([
function (next) {
db.incrObjectFieldBy('global', 'postCount', postCountChange, next);
},
function (next) {
db.incrObjectFieldBy('category:' + topicData.cid, 'post_count', postCountChange, next);
},
function (next) {
db.incrObjectFieldBy('category:' + topicData.cid, 'topic_count', incr, next);
},
], next);
});
async.parallel([
function (next) {
db.incrObjectFieldBy('global', 'postCount', postCountChange, next);
},
function (next) {
db.incrObjectFieldBy('category:' + topicData.cid, 'post_count', postCountChange, next);
},
function (next) {
db.incrObjectFieldBy('category:' + topicData.cid, 'topic_count', incr, next);
},
], next);
},
], next);
},
], callback);
}

View File

@@ -83,16 +83,21 @@ var emailer = require('../emailer');
}
});
},
function (next) {
next(null, confirm_code);
},
], callback);
};
UserEmail.confirm = function (code, callback) {
db.getObject('confirm:' + code, function (err, confirmObj) {
if (err) {
return callback(new Error('[[error:parse-error]]'));
}
if (confirmObj && confirmObj.uid && confirmObj.email) {
async.waterfall([
function (next) {
db.getObject('confirm:' + code, next);
},
function (confirmObj, next) {
if (!confirmObj || !confirmObj.uid || !confirmObj.email) {
return next(new Error('[[error:invalid-data]]'));
}
async.series([
async.apply(user.setUserField, confirmObj.uid, 'email:confirmed', 1),
async.apply(db.delete, 'confirm:' + code),
@@ -103,12 +108,10 @@ var emailer = require('../emailer');
function (next) {
plugins.fireHook('action:user.email.confirmed', { uid: confirmObj.uid, email: confirmObj.email }, next);
},
], function (err) {
callback(err ? new Error('[[error:email-confirm-failed]]') : null);
});
} else {
callback(new Error('[[error:invalid-data]]'));
}
], next);
},
], function (err) {
callback(err);
});
};
}(exports));

View File

@@ -279,6 +279,7 @@ module.exports = function (User) {
async.parallel([
async.apply(User.setUserField, data.uid, 'password', hashedPassword),
async.apply(User.reset.updateExpiry, data.uid),
async.apply(User.auth.revokeAllSessions, data.uid),
], function (err) {
next(err);
});