diff --git a/src/postTools.js b/src/postTools.js index 5d1132cf8e..217c3d616a 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -1,17 +1,17 @@ -var db = require('./database'), +var winston = require('winston'), + async = require('async'), + nconf = require('nconf'), + validator = require('validator'), + + db = require('./database'), posts = require('./posts'), topics = require('./topics'), threadTools = require('./threadTools'), user = require('./user'), websockets = require('./websockets'), - async = require('async'), - nconf = require('nconf'), - validator = require('validator'), - utils = require('../public/src/utils'), plugins = require('./plugins'), - - winston = require('winston'), + events = require('./events'), meta = require('./meta'), Feed = require('./feed'); @@ -70,20 +70,13 @@ var db = require('./database'), PostTools.edit = function(uid, pid, title, content) { var success = function() { - async.waterfall([ - function(next) { - posts.setPostField(pid, 'edited', Date.now()); - next(null); - }, - function(next) { - posts.setPostField(pid, 'editor', uid); - next(null); - }, - function(next) { - posts.setPostField(pid, 'content', content); - next(null); - } - ]); + posts.setPostFields(pid, { + edited: Date.now(), + editor: uid, + content: content + }); + + events.logPostEdit(uid, pid); db.searchRemove('post', pid, function() { db.searchIndex('post', content, pid); @@ -136,6 +129,8 @@ var db = require('./database'), db.decrObjectField('global', 'postCount'); db.searchRemove('post', pid); + events.logPostDelete(uid, pid); + posts.getPostFields(pid, ['tid', 'uid'], function(err, postData) { db.incrObjectFieldBy('topic:' + postData.tid, 'postcount', -1); @@ -190,6 +185,8 @@ var db = require('./database'), posts.setPostField(pid, 'deleted', 0); db.incrObjectField('global', 'postCount'); + events.logPostRestore(uid, pid); + posts.getPostFields(pid, ['tid', 'uid', 'content'], function(err, postData) { db.incrObjectFieldBy('topic:' + postData.tid, 'postcount', 1); diff --git a/src/posts.js b/src/posts.js index 74c9e2fb0f..29879cd5c2 100644 --- a/src/posts.js +++ b/src/posts.js @@ -332,7 +332,7 @@ var db = require('./database'), callback(null, newData); }); }); - } + }; Posts.getPostFields = function(pid, fields, callback) { db.getObjectFields('post:' + pid, fields, function(err, data) { @@ -352,7 +352,7 @@ var db = require('./database'), callback(null, data); }); }); - } + }; Posts.getPostField = function(pid, field, callback) { Posts.getPostFields(pid, [field], function(err, data) { @@ -362,7 +362,7 @@ var db = require('./database'), callback(null, data[field]); }); - } + }; Posts.setPostField = function(pid, field, value, callback) { db.setObjectField('post:' + pid, field, value, callback); @@ -371,7 +371,11 @@ var db = require('./database'), 'field': field, 'value': value }); - } + }; + + Posts.setPostFields = function(pid, data, callback) { + db.setObject('post:' + pid, data, callback); + }; Posts.getPostsByPids = function(pids, callback) { var keys = []; diff --git a/src/routes/authentication.js b/src/routes/authentication.js index 5b4291d45d..759f8f20de 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -102,6 +102,7 @@ } passport.serializeUser(function(user, done) { + console.log('serializeUser'); done(null, user.uid); }); diff --git a/src/routes/debug.js b/src/routes/debug.js index da831fb8b8..6b32f8ad02 100644 --- a/src/routes/debug.js +++ b/src/routes/debug.js @@ -83,6 +83,7 @@ var DebugRoute = function(app) { user.pushNotifCount(2); res.send(); }); + }); }; diff --git a/src/threadTools.js b/src/threadTools.js index ba4ec6fe49..859d6faac4 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -1,15 +1,18 @@ -var db = require('./database'), +var winston = require('winston'), + nconf = require('nconf'), + async = require('async'), + + db = require('./database'), topics = require('./topics'), categories = require('./categories'), CategoryTools = require('./categoryTools'), user = require('./user'), - async = require('async'), notifications = require('./notifications'), posts = require('./posts'), meta = require('./meta'), - websockets = require('./websockets'); - winston = require('winston'), - nconf = require('nconf'), + websockets = require('./websockets'), + events = require('./events'); + (function(ThreadTools) { @@ -97,6 +100,8 @@ var db = require('./database'), db.searchRemove('topic', tid); + events.logTopicDelete(uid, tid); + websockets.in('topic_' + tid).emit('event:topic_deleted', { tid: tid, status: 'ok' @@ -112,6 +117,8 @@ var db = require('./database'), db.incrObjectField('global', 'topicCount'); ThreadTools.unlock(tid); + events.logTopicRestore(uid, tid); + websockets.in('topic_' + tid).emit('event:topic_restored', { tid: tid, status: 'ok' diff --git a/src/user.js b/src/user.js index 6a79652b08..5743c62c57 100644 --- a/src/user.js +++ b/src/user.js @@ -15,6 +15,7 @@ var bcrypt = require('bcrypt'), groups = require('./groups'), notifications = require('./notifications'), topics = require('./topics'), + events = require('./events'), websockets = require('./websockets'); @@ -260,6 +261,7 @@ var bcrypt = require('bcrypt'), User.setUserField(uid, 'picture', gravatarpicture); } returnData.gravatarpicture = gravatarpicture; + events.logEmailChange(uid, userData.email, data.email); next(null); }); return; @@ -302,7 +304,7 @@ var bcrypt = require('bcrypt'), if (res) { User.hashPassword(data.newPassword, function(err, hash) { User.setUserField(uid, 'password', hash); - + events.logPasswordChange(uid); callback(null); }); } else { @@ -809,6 +811,7 @@ var bcrypt = require('bcrypt'), User.hashPassword(password, function(err, hash) { User.setUserField(uid, 'password', hash); + events.logPasswordReset(uid); }); db.deleteObjectField('reset:uid', code);