Merge remote-tracking branch 'origin/master' into flagging-refactor

v1.18.x
Julian Lam 8 years ago
commit 5e109bb4a8

@ -27,3 +27,4 @@ node_js:
branches: branches:
only: only:
- master - master
- develop

@ -89,8 +89,7 @@ module.exports = function (Plugins) {
next(); next();
}, },
function (next) { function (next) {
var command = installed ? ('npm uninstall ' + id) : ('npm install ' + id + '@' + (version || 'latest')); runNpmCommand(type, id, version || 'latest', next);
runNpmCommand(command, next);
}, },
function (next) { function (next) {
Plugins.get(id, next); Plugins.get(id, next);
@ -102,12 +101,13 @@ module.exports = function (Plugins) {
], callback); ], callback);
} }
function runNpmCommand(command, callback) { function runNpmCommand(command, pkgName, version, callback) {
require('child_process').exec(command, function (err, stdout) { require('child_process').execFile('npm', [command, pkgName + (command === 'install' ? '@' + version : '')], function (err, stdout) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
winston.verbose('[plugins] ' + stdout);
winston.verbose('[plugins/' + command + '] ' + stdout);
callback(); callback();
}); });
} }
@ -119,9 +119,7 @@ module.exports = function (Plugins) {
function upgrade(id, version, callback) { function upgrade(id, version, callback) {
async.waterfall([ async.waterfall([
function (next) { async.apply(runNpmCommand, 'install', id, version || 'latest'),
runNpmCommand('npm install ' + id + '@' + (version || 'latest'), next);
},
function (next) { function (next) {
Plugins.isActive(id, next); Plugins.isActive(id, next);
}, },

@ -149,7 +149,7 @@ module.exports = function (app, middleware, hotswapIds) {
app.use(relativePath, express.static(path.join(__dirname, '../../', 'public'), { app.use(relativePath, express.static(path.join(__dirname, '../../', 'public'), {
maxAge: app.enabled('cache') ? 5184000000 : 0 maxAge: app.enabled('cache') ? 5184000000 : 0
})); }));
app.use('/vendor/jquery/timeago/locales', middleware.processTimeagoLocales); app.use(relativePath + '/vendor/jquery/timeago/locales', middleware.processTimeagoLocales);
app.use(controllers.handle404); app.use(controllers.handle404);
app.use(controllers.handleURIErrors); app.use(controllers.handleURIErrors);
app.use(controllers.handleErrors); app.use(controllers.handleErrors);

@ -8,6 +8,7 @@ var groups = require('../../groups');
var user = require('../../user'); var user = require('../../user');
var events = require('../../events'); var events = require('../../events');
var meta = require('../../meta'); var meta = require('../../meta');
var plugins = require('../../plugins');
var User = {}; var User = {};
@ -169,6 +170,13 @@ function deleteUsers(socket, uids, method, callback) {
uid: socket.uid, uid: socket.uid,
targetUid: uid, targetUid: uid,
ip: socket.ip ip: socket.ip
}, next);
},
function (next) {
plugins.fireHook('action:user.delete', {
callerUid: socket.uid,
uid: uid,
ip: socket.ip
}); });
next(); next();
} }

@ -5,50 +5,65 @@ var user = require('../../user');
var websockets = require('../index'); var websockets = require('../index');
var events = require('../../events'); var events = require('../../events');
var plugins = require('../../plugins');
module.exports = function (SocketUser) { module.exports = function (SocketUser) {
SocketUser.banUsers = function (socket, data, callback) { SocketUser.banUsers = function (socket, data, callback) {
// Backwards compatibility if (!data || !Array.isArray(data.uids)) {
if (Array.isArray(data)) { return callback(new Error('[[error:invalid-data]]'));
data = {
uids: data,
until: 0,
reason: ''
};
} }
toggleBan(socket.uid, data.uids, function (uid, next) { toggleBan(socket.uid, data.uids, function (uid, next) {
async.waterfall([
function (next) {
banUser(uid, data.until || 0, data.reason || '', next); banUser(uid, data.until || 0, data.reason || '', next);
}, function (err) { },
if (err) { function (next) {
return callback(err);
}
async.each(data.uids, function (uid, next) {
events.log({ events.log({
type: 'user-ban', type: 'user-ban',
uid: socket.uid, uid: socket.uid,
targetUid: uid, targetUid: uid,
ip: socket.ip ip: socket.ip
}, next); }, next);
}, callback); },
function (next) {
plugins.fireHook('action:user.banned', {
callerUid: socket.uid,
ip: socket.ip,
uid: uid,
until: data.until > 0 ? data.until : undefined
}); });
next();
}
], next);
}, callback);
}; };
SocketUser.unbanUsers = function (socket, uids, callback) { SocketUser.unbanUsers = function (socket, uids, callback) {
toggleBan(socket.uid, uids, user.unban, function (err) { toggleBan(socket.uid, uids, function (uid, next) {
if (err) { async.waterfall([
return callback(err); function (next) {
} user.unban(uid, next);
},
async.each(uids, function (uid, next) { function (next) {
events.log({ events.log({
type: 'user-unban', type: 'user-unban',
uid: socket.uid, uid: socket.uid,
targetUid: uid, targetUid: uid,
ip: socket.ip ip: socket.ip
}, next); }, next);
}, callback); },
function (next) {
plugins.fireHook('action:user.unbanned', {
callerUid: socket.uid,
ip: socket.ip,
uid: uid
}); });
next();
}
], next);
}, callback);
}; };
function toggleBan(uid, uids, method, callback) { function toggleBan(uid, uids, method, callback) {

@ -3,6 +3,7 @@
var async = require('async'); var async = require('async');
var winston = require('winston'); var winston = require('winston');
var path = require('path'); var path = require('path');
var nconf = require('nconf');
var user = require('../../user'); var user = require('../../user');
var plugins = require('../../plugins'); var plugins = require('../../plugins');
@ -84,12 +85,15 @@ module.exports = function (SocketUser) {
}, },
function (userData, next) { function (userData, next) {
if (userData.uploadedpicture && !userData.uploadedpicture.startsWith('http')) { if (userData.uploadedpicture && !userData.uploadedpicture.startsWith('http')) {
require('fs').unlink(path.join(__dirname, '../../../public', userData.uploadedpicture), function (err) { var pathToFile = path.join(nconf.get('base_dir'), 'public', userData.uploadedpicture);
if (pathToFile.startsWith(path.join(nconf.get('base_dir'), nconf.get('upload_path')))) {
require('fs').unlink(pathToFile, function (err) {
if (err) { if (err) {
winston.error(err); winston.error(err);
} }
}); });
} }
}
user.setUserFields(data.uid, { user.setUserFields(data.uid, {
uploadedpicture: '', uploadedpicture: '',

@ -42,15 +42,7 @@ module.exports = function (User) {
} }
async.series(tasks, function (err) { async.series(tasks, function (err) {
if (err) { callback(err);
return callback(err);
}
plugins.fireHook('action:user.banned', {
uid: uid,
until: until > 0 ? until : undefined
});
callback();
}); });
}; };
@ -61,10 +53,6 @@ module.exports = function (User) {
}, },
function (next) { function (next) {
db.sortedSetsRemove(['users:banned', 'users:banned:expire'], uid, next); db.sortedSetsRemove(['users:banned', 'users:banned:expire'], uid, next);
},
function (next) {
plugins.fireHook('action:user.unbanned', {uid: uid});
next();
} }
], callback); ], callback);
}; };

@ -88,7 +88,7 @@ module.exports = function (User) {
}, },
function (next) { function (next) {
var sets = ['users:joindate', 'users:online']; var sets = ['users:joindate', 'users:online'];
if (parseInt(userData.uid) !== 1) { if (parseInt(userData.uid, 10) !== 1) {
sets.push('users:notvalidated'); sets.push('users:notvalidated');
} }
db.sortedSetsAdd(sets, timestamp, userData.uid, next); db.sortedSetsAdd(sets, timestamp, userData.uid, next);

@ -14,7 +14,7 @@ module.exports = function (User) {
User.updateProfile = function (uid, data, callback) { User.updateProfile = function (uid, data, callback) {
var fields = ['username', 'email', 'fullname', 'website', 'location', var fields = ['username', 'email', 'fullname', 'website', 'location',
'groupTitle', 'birthday', 'signature', 'aboutme', 'picture', 'uploadedpicture']; 'groupTitle', 'birthday', 'signature', 'aboutme'];
async.waterfall([ async.waterfall([
function (next) { function (next) {
@ -147,32 +147,34 @@ module.exports = function (User) {
} }
function updateEmail(uid, newEmail, callback) { function updateEmail(uid, newEmail, callback) {
User.getUserFields(uid, ['email', 'picture', 'uploadedpicture'], function (err, userData) { async.waterfall([
if (err) { function (next) {
return callback(err); User.getUserField(uid, 'email', next);
} },
function (oldEmail, next) {
userData.email = userData.email || ''; oldEmail = oldEmail || '';
if (userData.email === newEmail) { if (oldEmail === newEmail) {
return callback(); return callback();
} }
async.series([ async.series([
async.apply(db.sortedSetRemove, 'email:uid', userData.email.toLowerCase()), async.apply(db.sortedSetRemove, 'email:uid', oldEmail.toLowerCase()),
async.apply(db.sortedSetRemove, 'email:sorted', userData.email.toLowerCase() + ':' + uid) async.apply(db.sortedSetRemove, 'email:sorted', oldEmail.toLowerCase() + ':' + uid)
], function (err) { ], function (err) {
if (err) { next(err);
return callback(err); });
} },
function (next) {
async.parallel([ async.parallel([
function (next) { function (next) {
db.sortedSetAdd('email:uid', uid, newEmail.toLowerCase(), next); db.sortedSetAdd('email:uid', uid, newEmail.toLowerCase(), next);
}, },
async.apply(db.sortedSetAdd, 'user:' + uid + ':emails', Date.now(), newEmail + ':' + Date.now()),
function (next) { function (next) {
db.sortedSetAdd('email:sorted', 0, newEmail.toLowerCase() + ':' + uid, next); db.sortedSetAdd('email:sorted', 0, newEmail.toLowerCase() + ':' + uid, next);
}, },
function (next) {
db.sortedSetAdd('user:' + uid + ':emails', Date.now(), newEmail + ':' + Date.now(), next);
},
function (next) { function (next) {
User.setUserField(uid, 'email', newEmail, next); User.setUserField(uid, 'email', newEmail, next);
}, },
@ -185,10 +187,12 @@ module.exports = function (User) {
function (next) { function (next) {
db.sortedSetAdd('users:notvalidated', Date.now(), uid, next); db.sortedSetAdd('users:notvalidated', Date.now(), uid, next);
} }
], callback); ], function (err) {
}); next(err);
}); });
} }
], callback);
}
function updateUsername(uid, newUsername, callback) { function updateUsername(uid, newUsername, callback) {
if (!newUsername) { if (!newUsername) {

Loading…
Cancel
Save