mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-09-02 11:28:00 +02:00
Merge remote-tracking branch 'origin/master' into LevelDB
Conflicts: tests/database.js
This commit is contained in:
@@ -64,7 +64,7 @@ var db = require('./database'),
|
||||
Categories.getCategoryById = function(cid, start, end, uid, callback) {
|
||||
Categories.getCategoryData(cid, function(err, category) {
|
||||
if(err || !category) {
|
||||
return callback(err || new Error('category-not-found [' + cid + ']'));
|
||||
return callback(err || new Error('[[error:invalid-cid]]'));
|
||||
}
|
||||
|
||||
if(parseInt(uid, 10)) {
|
||||
@@ -278,7 +278,7 @@ var db = require('./database'),
|
||||
Categories.getCategories = function(cids, uid, callback) {
|
||||
|
||||
if (!Array.isArray(cids) || cids.length === 0) {
|
||||
return callback(new Error('invalid-cids'));
|
||||
return callback(new Error('[[error:invalid-cid]]'));
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
|
||||
@@ -33,7 +33,7 @@ function userNotAllowed(res) {
|
||||
function getUserDataByUserSlug(userslug, callerUID, callback) {
|
||||
user.getUidByUserslug(userslug, function(err, uid) {
|
||||
if(err || !uid) {
|
||||
return callback(err || new Error('invalid-user'));
|
||||
return callback(err || new Error('[[error:invalid-uid]]'));
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
@@ -54,7 +54,7 @@ function getUserDataByUserSlug(userslug, callerUID, callback) {
|
||||
}
|
||||
}, function(err, results) {
|
||||
if(err || !results.userData) {
|
||||
return callback(err || new Error('invalid-user'));
|
||||
return callback(err || new Error('[[error:invalid-uid]]'));
|
||||
}
|
||||
|
||||
var userData = results.userData;
|
||||
|
||||
@@ -70,7 +70,7 @@ categoriesController.get = function(req, res, next) {
|
||||
categoryTools.privileges(cid, uid, function(err, categoryPrivileges) {
|
||||
if (!err) {
|
||||
if (!categoryPrivileges.read) {
|
||||
next(new Error('not-enough-privileges'));
|
||||
next(new Error('[[error:no-privileges]]'));
|
||||
} else {
|
||||
next(null, categoryPrivileges);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ categoriesController.get = function(req, res, next) {
|
||||
|
||||
if (categoryData) {
|
||||
if (parseInt(categoryData.disabled, 10) === 1) {
|
||||
return next(new Error('Category disabled'), null);
|
||||
return next(new Error('[[error:category-disabled]]'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ topicsController.get = function(req, res, next) {
|
||||
}
|
||||
|
||||
if (!userPrivileges.read) {
|
||||
return next(new Error('not-enough-privileges'));
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
|
||||
privileges = userPrivileges;
|
||||
@@ -45,7 +45,7 @@ topicsController.get = function(req, res, next) {
|
||||
topics.getTopicWithPosts(tid, uid, start, end, function (err, topicData) {
|
||||
if (topicData) {
|
||||
if (parseInt(topicData.deleted, 10) === 1 && parseInt(topicData.expose_tools, 10) === 0) {
|
||||
return next(new Error('Topic deleted'));
|
||||
return next(new Error('[[error:no-topic]]'));
|
||||
}
|
||||
topicData.currentPage = page;
|
||||
}
|
||||
|
||||
@@ -538,21 +538,15 @@
|
||||
getSortedSetRange(key, start, stop, -1, callback);
|
||||
};
|
||||
|
||||
module.getSortedSetRangeByScore = function(args, callback) {
|
||||
getSortedSetRangeByScore(args, 1, callback);
|
||||
module.getSortedSetRangeByScore = function(key, start, count, min, max, callback) {
|
||||
getSortedSetRangeByScore(key, start, count, min, max, 1, callback);
|
||||
};
|
||||
|
||||
module.getSortedSetRevRangeByScore = function(args, callback) {
|
||||
getSortedSetRangeByScore(args, -1, callback);
|
||||
module.getSortedSetRevRangeByScore = function(key, start, count, max, min, callback) {
|
||||
getSortedSetRangeByScore(key, start, count, min, max, -1, callback);
|
||||
};
|
||||
|
||||
function getSortedSetRangeByScore(args, sort, callback) {
|
||||
var key = args[0],
|
||||
max = (args[1] === '+inf') ? Number.MAX_VALUE : args[1],
|
||||
min = args[2],
|
||||
start = args[4],
|
||||
count = args[5];
|
||||
|
||||
function getSortedSetRangeByScore(key, start, count, min, max, sort, callback) {
|
||||
if(parseInt(count, 10) === -1) {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
@@ -359,12 +359,12 @@
|
||||
redisClient.zrevrange(key, start, stop, callback);
|
||||
};
|
||||
|
||||
module.getSortedSetRangeByScore = function(args, callback) {
|
||||
redisClient.zrangebyscore(args, callback);
|
||||
module.getSortedSetRangeByScore = function(key, start, count, min, max, callback) {
|
||||
redisClient.zrangebyscore([key, min, max, 'LIMIT', start, count], callback);
|
||||
};
|
||||
|
||||
module.getSortedSetRevRangeByScore = function(args, callback) {
|
||||
redisClient.zrevrangebyscore(args, callback);
|
||||
module.getSortedSetRevRangeByScore = function(key, start, count, max, min, callback) {
|
||||
redisClient.zrevrangebyscore([key, max, min, 'LIMIT', start, count], callback);
|
||||
};
|
||||
|
||||
module.sortedSetCount = function(key, min, max, callback) {
|
||||
|
||||
@@ -8,67 +8,50 @@ var async = require('async'),
|
||||
(function (Favourites) {
|
||||
"use strict";
|
||||
|
||||
function vote(type, unvote, pid, room_id, uid, socket, callback) {
|
||||
var websockets = require('./socket.io');
|
||||
function vote(type, unvote, pid, uid, callback) {
|
||||
uid = parseInt(uid, 10);
|
||||
|
||||
if (uid === 0) {
|
||||
return socket.emit('event:alert', {
|
||||
alert_id: 'post_vote',
|
||||
title: '[[topic:vote.not_logged_in.title]]',
|
||||
message: '[[topic:vote.not_logged_in.message]]',
|
||||
type: 'danger',
|
||||
timeout: 5000
|
||||
});
|
||||
return callback(new Error('[[error:not-logged-in]]'));
|
||||
}
|
||||
|
||||
posts.getPostFields(pid, ['uid', 'timestamp'], function (err, postData) {
|
||||
if (uid === parseInt(postData.uid, 10)) {
|
||||
socket.emit('event:alert', {
|
||||
alert_id: 'post_vote',
|
||||
title: '[[topic:vote.cant_vote_self.title]]',
|
||||
message: '[[topic:vote.cant_vote_self.message]]',
|
||||
type: 'danger',
|
||||
timeout: 5000
|
||||
});
|
||||
|
||||
if (callback) {
|
||||
callback(false);
|
||||
}
|
||||
|
||||
return false;
|
||||
posts.getPostFields(pid, ['pid', 'uid', 'timestamp'], function (err, postData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(type === 'upvote' || !unvote) {
|
||||
db.sortedSetAdd('uid: ' + uid + ':upvote', postData.timestamp, pid);
|
||||
if (uid === parseInt(postData.uid, 10)) {
|
||||
return callback(new Error('[[error:cant-vote-self-post]]'));
|
||||
}
|
||||
|
||||
if(type === 'upvote' && !unvote) {
|
||||
db.sortedSetAdd('uid:' + uid + ':upvote', postData.timestamp, pid);
|
||||
} else {
|
||||
db.sortedSetRemove('uid: ' + uid + ':upvote', pid);
|
||||
db.sortedSetRemove('uid:' + uid + ':upvote', pid);
|
||||
}
|
||||
|
||||
if(type === 'upvote' || unvote) {
|
||||
db.sortedSetRemove('uid: ' + uid + ':downvote', pid);
|
||||
db.sortedSetRemove('uid:' + uid + ':downvote', pid);
|
||||
} else {
|
||||
db.sortedSetAdd('uid: ' + uid + ':downvote', postData.timestamp, pid);
|
||||
db.sortedSetAdd('uid:' + uid + ':downvote', postData.timestamp, pid);
|
||||
}
|
||||
|
||||
user[type === 'upvote' ? 'incrementUserFieldBy' : 'decrementUserFieldBy'](postData.uid, 'reputation', 1, function (err, newreputation) {
|
||||
db.sortedSetAdd('users:reputation', newreputation, postData.uid);
|
||||
});
|
||||
|
||||
if (room_id) {
|
||||
websockets.in(room_id).emit('event:' + (type === 'upvote' ? 'rep_up' : 'rep_down'), {
|
||||
uid: postData.uid,
|
||||
pid: pid
|
||||
});
|
||||
}
|
||||
|
||||
socket.emit('posts.' + (unvote ? 'unvote' : type), {
|
||||
pid: pid
|
||||
});
|
||||
|
||||
adjustPostVotes(pid, uid, type, unvote, function() {
|
||||
if (callback) {
|
||||
callback();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.sortedSetAdd('users:reputation', newreputation, postData.uid);
|
||||
|
||||
adjustPostVotes(pid, uid, type, unvote, function(err, votes) {
|
||||
postData.votes = votes;
|
||||
callback(err, {
|
||||
user: {
|
||||
reputation: newreputation
|
||||
},
|
||||
post: postData
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -79,21 +62,19 @@ var async = require('async'),
|
||||
async.series([
|
||||
function(next) {
|
||||
if (unvote) {
|
||||
db.setRemove('pid:' + pid + ':' + type, uid, function(err) {
|
||||
next(err);
|
||||
});
|
||||
db.setRemove('pid:' + pid + ':' + type, uid, next);
|
||||
} else {
|
||||
db.setAdd('pid:' + pid + ':' + type, uid, function(err) {
|
||||
next(err);
|
||||
});
|
||||
db.setAdd('pid:' + pid + ':' + type, uid, next);
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
db.setRemove('pid:' + pid + ':' + notType, uid, function(err) {
|
||||
next(err);
|
||||
});
|
||||
db.setRemove('pid:' + pid + ':' + notType, uid, next);
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
upvotes: function(next) {
|
||||
db.setCount('pid:' + pid + ':upvote', next);
|
||||
@@ -102,48 +83,46 @@ var async = require('async'),
|
||||
db.setCount('pid:' + pid + ':downvote', next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
posts.setPostField(pid, 'votes', parseInt(results.upvotes, 10) - parseInt(results.downvotes, 10));
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var voteCount = parseInt(results.upvotes, 10) - parseInt(results.downvotes, 10);
|
||||
posts.setPostField(pid, 'votes', voteCount, function(err) {
|
||||
callback(err, voteCount);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback();
|
||||
Favourites.upvote = function(pid, uid, callback) {
|
||||
toggleVote('upvote', pid, uid, callback);
|
||||
};
|
||||
|
||||
Favourites.downvote = function(pid, uid, callback) {
|
||||
toggleVote('downvote', pid, uid, callback);
|
||||
};
|
||||
|
||||
function toggleVote(type, pid, uid, callback) {
|
||||
Favourites.unvote(pid, uid, function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
vote(type, false, pid, uid, callback);
|
||||
});
|
||||
}
|
||||
|
||||
Favourites.upvote = function(pid, room_id, uid, socket) {
|
||||
toggleVote('upvote', pid, room_id, uid, socket);
|
||||
};
|
||||
|
||||
Favourites.downvote = function(pid, room_id, uid, socket) {
|
||||
toggleVote('downvote', pid, room_id, uid, socket);
|
||||
};
|
||||
|
||||
function toggleVote(type, pid, room_id, uid, socket) {
|
||||
Favourites.unvote(pid, room_id, uid, socket, function(err) {
|
||||
vote(type, false, pid, room_id, uid, socket);
|
||||
});
|
||||
}
|
||||
|
||||
Favourites.unvote = function(pid, room_id, uid, socket, callback) {
|
||||
var websockets = require('./socket.io');
|
||||
|
||||
Favourites.unvote = function(pid, uid, callback) {
|
||||
Favourites.hasVoted(pid, uid, function(err, voteStatus) {
|
||||
if (voteStatus.upvoted || voteStatus.downvoted) {
|
||||
socket.emit('posts.unvote', {
|
||||
pid: pid
|
||||
});
|
||||
|
||||
return vote(voteStatus.upvoted ? 'downvote' : 'upvote', true, pid, room_id, uid, socket, function() {
|
||||
if (callback) {
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(err);
|
||||
if (!voteStatus || (!voteStatus.upvoted && !voteStatus.downvoted)) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
vote(voteStatus.upvoted ? 'downvote' : 'upvote', true, pid, uid, callback);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -164,77 +143,64 @@ var async = require('async'),
|
||||
}, callback);
|
||||
};
|
||||
|
||||
Favourites.favourite = function (pid, room_id, uid, socket) {
|
||||
var websockets = require('./socket.io');
|
||||
Favourites.favourite = function (pid, uid, callback) {
|
||||
toggleFavourite('favourite', pid, uid, callback);
|
||||
};
|
||||
|
||||
Favourites.unfavourite = function(pid, uid, callback) {
|
||||
toggleFavourite('unfavourite', pid, uid, callback);
|
||||
};
|
||||
|
||||
function toggleFavourite(type, pid, uid, callback) {
|
||||
if (uid === 0) {
|
||||
return socket.emit('event:alert', {
|
||||
alert_id: 'post_favourite',
|
||||
title: '[[topic:favourites.not_logged_in.title]]',
|
||||
message: '[[topic:favourites.not_logged_in.message]]',
|
||||
type: 'danger',
|
||||
timeout: 5000
|
||||
});
|
||||
return callback(new Error('[[error:not-logged-in]]'));
|
||||
}
|
||||
|
||||
posts.getPostFields(pid, ['uid', 'timestamp'], function (err, postData) {
|
||||
posts.getPostFields(pid, ['pid', 'uid', 'timestamp'], function (err, postData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Favourites.hasFavourited(pid, uid, function (err, hasFavourited) {
|
||||
if (!hasFavourited) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (type === 'favourite' && hasFavourited) {
|
||||
return callback(new Error('[[error:already-favourited]]'));
|
||||
}
|
||||
|
||||
if (type === 'unfavourite' && !hasFavourited) {
|
||||
return callback(new Error('[[error:alrady-unfavourited]]'));
|
||||
}
|
||||
|
||||
if (type === 'favourite') {
|
||||
db.sortedSetAdd('uid:' + uid + ':favourites', postData.timestamp, pid);
|
||||
db.setAdd('pid:' + pid + ':users_favourited', uid, function(err) {
|
||||
db.setCount('pid:' + pid + ':users_favourited', function(err, count) {
|
||||
posts.setPostField(pid, 'reputation', count);
|
||||
});
|
||||
});
|
||||
|
||||
if (room_id) {
|
||||
websockets.in(room_id).emit('event:favourited', {
|
||||
uid: uid !== postData.uid ? postData.uid : 0,
|
||||
pid: pid
|
||||
});
|
||||
}
|
||||
|
||||
socket.emit('posts.favourite', {
|
||||
pid: pid
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Favourites.unfavourite = function(pid, room_id, uid, socket) {
|
||||
var websockets = require('./socket.io');
|
||||
|
||||
if (uid === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
posts.getPostField(pid, 'uid', function (err, uid_of_poster) {
|
||||
Favourites.hasFavourited(pid, uid, function (err, hasFavourited) {
|
||||
if (hasFavourited) {
|
||||
} else {
|
||||
db.sortedSetRemove('uid:' + uid + ':favourites', pid);
|
||||
db.setRemove('pid:' + pid + ':users_favourited', uid, function(err) {
|
||||
db.setCount('pid:' + pid + ':users_favourited', function(err, count) {
|
||||
posts.setPostField(pid, 'reputation', count);
|
||||
}
|
||||
|
||||
|
||||
db[type === 'favourite' ? 'setAdd' : 'setRemove']('pid:' + pid + ':users_favourited', uid, function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.setCount('pid:' + pid + ':users_favourited', function(err, count) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
postData.reputation = count;
|
||||
posts.setPostField(pid, 'reputation', count, function(err) {
|
||||
callback(err, {
|
||||
post: postData
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (room_id) {
|
||||
websockets.in(room_id).emit('event:unfavourited', {
|
||||
uid: uid !== uid_of_poster ? uid_of_poster : 0,
|
||||
pid: pid
|
||||
});
|
||||
}
|
||||
|
||||
if (socket) {
|
||||
socket.emit('posts.unfavourite', {
|
||||
pid: pid
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Favourites.hasFavourited = function(pid, uid, callback) {
|
||||
db.isSetMember('pid:' + pid + ':users_favourited', uid, callback);
|
||||
|
||||
@@ -137,7 +137,7 @@
|
||||
|
||||
Groups.create = function(name, description, callback) {
|
||||
if (name.length === 0) {
|
||||
return callback(new Error('name-too-short'));
|
||||
return callback(new Error('[[error:group-name-too-short]]'));
|
||||
}
|
||||
|
||||
if (name === 'administrators' || name === 'registered-users') {
|
||||
@@ -145,28 +145,32 @@
|
||||
}
|
||||
|
||||
Groups.exists(name, function (err, exists) {
|
||||
if (!exists) {
|
||||
var groupData = {
|
||||
name: name,
|
||||
description: description,
|
||||
deleted: '0',
|
||||
hidden: '0',
|
||||
system: system ? '1' : '0'
|
||||
};
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.setAdd('groups', name, next);
|
||||
},
|
||||
function(next) {
|
||||
db.setObject('group:' + name, groupData, function(err) {
|
||||
Groups.get(name, {}, next);
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
} else {
|
||||
callback(new Error('group-exists'));
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
return callback(new Error('[[error:group-already-exists]]'));
|
||||
}
|
||||
|
||||
var groupData = {
|
||||
name: name,
|
||||
description: description,
|
||||
deleted: '0',
|
||||
hidden: '0',
|
||||
system: system ? '1' : '0'
|
||||
};
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.setAdd('groups', name, next);
|
||||
},
|
||||
function(next) {
|
||||
db.setObject('group:' + name, groupData, function(err) {
|
||||
Groups.get(name, {}, next);
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -184,12 +188,12 @@
|
||||
db.setObject('group:' + groupName, values, callback);
|
||||
} else {
|
||||
if (callback) {
|
||||
callback(new Error('name-change-not-allowed'));
|
||||
callback(new Error('[[error:group-name-change-not-allowed]]'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (callback) {
|
||||
callback(new Error('gid-not-found'));
|
||||
callback(new Error('[[error:no-group]]'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -120,7 +120,7 @@ var winston = require('winston'),
|
||||
|
||||
PostTools.privileges(pid, uid, function(err, privileges) {
|
||||
if (err || !privileges.editable) {
|
||||
return callback(err || new Error('not-privileges-to-edit'));
|
||||
return callback(err || new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
|
||||
posts.getPostData(pid, function(err, postData) {
|
||||
@@ -155,15 +155,15 @@ var winston = require('winston'),
|
||||
},
|
||||
function(deleted, next) {
|
||||
if(parseInt(deleted, 10) === 1 && isDelete) {
|
||||
return next(new Error('Post already deleted'));
|
||||
return next(new Error('[[error:post-already-deleted]]'));
|
||||
} else if(parseInt(deleted, 10) !== 1 && !isDelete) {
|
||||
return next(new Error('Post already restored'));
|
||||
return next(new Error('[[error:post-already-restored]]'));
|
||||
}
|
||||
PostTools.privileges(pid, uid, next);
|
||||
},
|
||||
function(privileges, next) {
|
||||
if (!privileges || !privileges.editable) {
|
||||
return next(new Error('no privileges'));
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ var db = require('./database'),
|
||||
toPid = data.toPid;
|
||||
|
||||
if (uid === null) {
|
||||
return callback(new Error('invalid-user'));
|
||||
return callback(new Error('[[error:invalid-uid]]'));
|
||||
}
|
||||
|
||||
var timestamp = Date.now(),
|
||||
@@ -210,7 +210,7 @@ var db = require('./database'),
|
||||
|
||||
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
|
||||
|
||||
db.getSortedSetRevRangeByScore(['posts:pid', '+inf', Date.now() - since, 'LIMIT', start, count], function(err, pids) {
|
||||
db.getSortedSetRevRangeByScore('posts:pid', start, count, Infinity, Date.now() - since, function(err, pids) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -420,7 +420,7 @@ var db = require('./database'),
|
||||
|
||||
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||
if(err || !cid) {
|
||||
return callback(err || new Error('invalid-category-id'));
|
||||
return callback(err || new Error('[[error:invalid-cid]]'));
|
||||
}
|
||||
callback(null, cid);
|
||||
});
|
||||
@@ -458,7 +458,7 @@ var db = require('./database'),
|
||||
|
||||
Posts.getPidPage = function(pid, uid, callback) {
|
||||
if(!pid) {
|
||||
return callback(new Error('invalid-pid'));
|
||||
return callback(new Error('[[error:invalid-pid]]'));
|
||||
}
|
||||
|
||||
var index = 0;
|
||||
|
||||
@@ -63,14 +63,14 @@ function uploadPost(req, res, next) {
|
||||
function uploadThumb(req, res, next) {
|
||||
if (!meta.config.allowTopicsThumbnail) {
|
||||
deleteTempFiles(req.files.files);
|
||||
return callback(new Error('Topic Thumbnails are disabled!'));
|
||||
return callback(new Error('[[error:topic-thumbnails-are-disabled]]'));
|
||||
}
|
||||
|
||||
upload(req, res, function(file, next) {
|
||||
if(file.type.match(/image./)) {
|
||||
uploadImage(file, next);
|
||||
} else {
|
||||
next(new Error('Invalid File'));
|
||||
next(new Error('[[error:invalid-file]]'));
|
||||
}
|
||||
}, next);
|
||||
}
|
||||
@@ -85,7 +85,7 @@ function uploadImage(image, callback) {
|
||||
if (meta.config.allowFileUploads) {
|
||||
uploadFile(image, callback);
|
||||
} else {
|
||||
callback(new Error('Uploads are disabled!'));
|
||||
callback(new Error('[[error:uploads-are-disabled]]'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,15 +97,15 @@ function uploadFile(file, callback) {
|
||||
} else {
|
||||
|
||||
if(!meta.config.allowFileUploads) {
|
||||
return callback(new Error('File uploads are not allowed'));
|
||||
return callback(new Error('[[error:uploads-are-disabled]]'));
|
||||
}
|
||||
|
||||
if(!file) {
|
||||
return callback(new Error('invalid file'));
|
||||
return callback(new Error('[[error:invalid-file]]'));
|
||||
}
|
||||
|
||||
if(file.size > parseInt(meta.config.maximumFileSize, 10) * 1024) {
|
||||
return callback(new Error('File too big'));
|
||||
return callback(new Error('[[error:file-too-big, ' + meta.config.maximumFileSize + ']]'));
|
||||
}
|
||||
|
||||
var filename = 'upload-' + utils.generateUUID() + path.extname(file.name);
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
|
||||
Auth.login = function(username, password, next) {
|
||||
if (!username || !password) {
|
||||
return next(new Error('invalid-user'));
|
||||
return next(new Error('[[error:invalid-user-data]]'));
|
||||
}
|
||||
|
||||
var userslug = utils.slugify(username);
|
||||
@@ -170,7 +170,7 @@
|
||||
|
||||
if(!uid) {
|
||||
// Even if a user doesn't exist, compare passwords anyway, so we don't immediately return
|
||||
return next(null, false, 'user doesn\'t exist');
|
||||
return next(null, false, '[[error:no-user]]');
|
||||
}
|
||||
|
||||
user.getUserFields(uid, ['password', 'banned'], function(err, userData) {
|
||||
@@ -179,11 +179,11 @@
|
||||
}
|
||||
|
||||
if (!userData || !userData.password) {
|
||||
return next(new Error('invalid userdata or password'));
|
||||
return next(new Error('[[error:invalid-user-data]]'));
|
||||
}
|
||||
|
||||
if (userData.banned && parseInt(userData.banned, 10) === 1) {
|
||||
return next(null, false, 'User banned');
|
||||
return next(null, false, '[[error:user-banned]]');
|
||||
}
|
||||
|
||||
bcrypt.compare(password, userData.password, function(err, res) {
|
||||
@@ -192,12 +192,12 @@
|
||||
}
|
||||
|
||||
if (!res) {
|
||||
return next(null, false, 'invalid-password');
|
||||
return next(null, false, '[[error:invalid-password]]');
|
||||
}
|
||||
|
||||
next(null, {
|
||||
uid: uid
|
||||
}, 'Authentication successful');
|
||||
}, '[[success:authentication-successful]]');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -79,7 +79,7 @@ SocketAdmin.user.removeAdmin = function(socket, theirid, callback) {
|
||||
|
||||
SocketAdmin.user.createUser = function(socket, userData, callback) {
|
||||
if (!userData) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
user.create(userData, callback);
|
||||
};
|
||||
@@ -87,7 +87,7 @@ SocketAdmin.user.createUser = function(socket, userData, callback) {
|
||||
SocketAdmin.user.banUser = function(socket, theirid, callback) {
|
||||
user.isAdministrator(theirid, function(err, isAdmin) {
|
||||
if (err || isAdmin) {
|
||||
return callback(err || new Error('You can\'t ban other admins!'));
|
||||
return callback(err || new Error('[[error:cant-ban-other-admins]]'));
|
||||
}
|
||||
|
||||
user.ban(theirid, function(err) {
|
||||
@@ -137,6 +137,10 @@ SocketAdmin.user.search = function(socket, username, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.each(data.users, isAdmin, function(err) {
|
||||
callback(err, data);
|
||||
});
|
||||
@@ -146,7 +150,7 @@ SocketAdmin.user.search = function(socket, username, callback) {
|
||||
/* Categories */
|
||||
SocketAdmin.categories.create = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
categories.create(data, callback);
|
||||
@@ -154,7 +158,7 @@ SocketAdmin.categories.create = function(socket, data, callback) {
|
||||
|
||||
SocketAdmin.categories.update = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
categories.update(data, callback);
|
||||
@@ -162,7 +166,7 @@ SocketAdmin.categories.update = function(socket, data, callback) {
|
||||
|
||||
SocketAdmin.categories.search = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
var username = data.username,
|
||||
@@ -184,7 +188,7 @@ SocketAdmin.categories.search = function(socket, data, callback) {
|
||||
|
||||
SocketAdmin.categories.setPrivilege = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
var cid = data.cid,
|
||||
@@ -248,15 +252,14 @@ SocketAdmin.categories.getPrivilegeSettings = function(socket, cid, callback) {
|
||||
callback(null, {
|
||||
"+r": data['+r'].members,
|
||||
"+w": data['+w'].members,
|
||||
"mods": data['mods'].members
|
||||
"mods": data.mods.members
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
SocketAdmin.categories.setGroupPrivilege = function(socket, data, callback) {
|
||||
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
if (data.set) {
|
||||
@@ -295,7 +298,7 @@ SocketAdmin.themes.getInstalled = function(socket, data, callback) {
|
||||
|
||||
SocketAdmin.themes.set = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
widgets.reset(function(err) {
|
||||
@@ -315,7 +318,7 @@ SocketAdmin.plugins.toggle = function(socket, plugin_id) {
|
||||
|
||||
SocketAdmin.widgets.set = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
widgets.setArea(data, callback);
|
||||
@@ -328,7 +331,7 @@ SocketAdmin.config.get = function(socket, data, callback) {
|
||||
|
||||
SocketAdmin.config.set = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
meta.configs.set(data.key, data.value, function(err) {
|
||||
@@ -354,7 +357,7 @@ SocketAdmin.config.remove = function(socket, key) {
|
||||
/* Groups */
|
||||
SocketAdmin.groups.create = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
groups.create(data.name, data.description, function(err, groupObj) {
|
||||
@@ -376,7 +379,7 @@ SocketAdmin.groups.get = function(socket, groupName, callback) {
|
||||
|
||||
SocketAdmin.groups.join = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
groups.join(data.groupName, data.uid, callback);
|
||||
@@ -384,7 +387,7 @@ SocketAdmin.groups.join = function(socket, data, callback) {
|
||||
|
||||
SocketAdmin.groups.leave = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
groups.leave(data.groupName, data.uid, callback);
|
||||
@@ -392,7 +395,7 @@ SocketAdmin.groups.leave = function(socket, data, callback) {
|
||||
|
||||
SocketAdmin.groups.update = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
groups.update(data.groupName, data.values, function(err) {
|
||||
|
||||
@@ -13,7 +13,7 @@ SocketCategories.getRecentReplies = function(socket, cid, callback) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (privileges && !privileges.read) {
|
||||
if (!privileges || !privileges.read) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ SocketCategories.get = function(socket, data, callback) {
|
||||
|
||||
SocketCategories.loadMore = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
user.getSettings(socket.uid, function(err, settings) {
|
||||
|
||||
@@ -37,7 +37,7 @@ SocketMeta.buildTitle = function(socket, text, callback) {
|
||||
|
||||
SocketMeta.updateHeader = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
if (socket.uid) {
|
||||
@@ -76,7 +76,7 @@ SocketMeta.getUsageStats = function(socket, data, callback) {
|
||||
|
||||
SocketMeta.rooms.enter = function(socket, data) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
if (data.leave !== null) {
|
||||
|
||||
@@ -49,35 +49,36 @@ var stopTracking = function(replyObj) {
|
||||
};
|
||||
|
||||
SocketModules.composer.push = function(socket, pid, callback) {
|
||||
if (socket.uid || parseInt(meta.config.allowGuestPosting, 10)) {
|
||||
if (parseInt(pid, 10) > 0) {
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
posts.getPostFields(pid, ['content'], next);
|
||||
},
|
||||
function(next) {
|
||||
topics.getTopicDataByPid(pid, next);
|
||||
},
|
||||
function(next) {
|
||||
posts.getPidIndex(pid, next);
|
||||
}
|
||||
], function(err, results) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
callback(null, {
|
||||
pid: pid,
|
||||
body: results[0].content,
|
||||
title: results[1].title,
|
||||
topic_thumb: results[1].thumb,
|
||||
index: results[2]
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
callback(new Error('no-uid'));
|
||||
if(!socket.uid && parseInt(meta.config.allowGuestPosting, 10) !== 1) {
|
||||
return callback(new Error('[[error:not-logged-in]]'));
|
||||
}
|
||||
|
||||
posts.getPostFields(pid, ['content'], function(err, postData) {
|
||||
if(err || (!postData && !postData.content)) {
|
||||
return callback(err || new Error('[[error:invalid-pid]]'));
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
topic: function(next) {
|
||||
topics.getTopicDataByPid(pid, next);
|
||||
},
|
||||
index: function(next) {
|
||||
posts.getPidIndex(pid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, {
|
||||
pid: pid,
|
||||
body: postData.content,
|
||||
title: results.topic.title,
|
||||
topic_thumb: results.topic.thumb,
|
||||
index: results.index
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
SocketModules.composer.editCheck = function(socket, pid, callback) {
|
||||
@@ -150,7 +151,7 @@ SocketModules.composer.getUsersByTid = function(socket, tid, callback) {
|
||||
|
||||
SocketModules.chats.get = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
Messaging.getMessages(socket.uid, data.touid, false, callback);
|
||||
@@ -158,7 +159,7 @@ SocketModules.chats.get = function(socket, data, callback) {
|
||||
|
||||
SocketModules.chats.send = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
var touid = data.touid;
|
||||
|
||||
@@ -11,7 +11,7 @@ var async = require('async'),
|
||||
notifications = require('../notifications'),
|
||||
groups = require('../groups'),
|
||||
user = require('../user'),
|
||||
index = require('./index'),
|
||||
websockets = require('./index'),
|
||||
|
||||
SocketPosts = {};
|
||||
|
||||
@@ -40,38 +40,50 @@ SocketPosts.reply = function(socket, data, callback) {
|
||||
posts: [postData]
|
||||
};
|
||||
|
||||
index.server.sockets.emit('event:new_post', socketData);
|
||||
websockets.server.sockets.emit('event:new_post', socketData);
|
||||
|
||||
callback();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
SocketPosts.upvote = function(socket, data) {
|
||||
favouriteCommand('upvote', socket, data);
|
||||
SocketPosts.upvote = function(socket, data, callback) {
|
||||
favouriteCommand('upvote', 'voted', socket, data, callback);
|
||||
sendNotificationToPostOwner(data, socket.uid, 'has upvoted your post');
|
||||
};
|
||||
|
||||
SocketPosts.downvote = function(socket, data) {
|
||||
favouriteCommand('downvote', socket, data);
|
||||
SocketPosts.downvote = function(socket, data, callback) {
|
||||
favouriteCommand('downvote', 'voted', socket, data, callback);
|
||||
};
|
||||
|
||||
SocketPosts.unvote = function(socket, data) {
|
||||
favouriteCommand('unvote', socket, data);
|
||||
SocketPosts.unvote = function(socket, data, callback) {
|
||||
favouriteCommand('unvote', 'voted', socket, data, callback);
|
||||
};
|
||||
|
||||
SocketPosts.favourite = function(socket, data) {
|
||||
favouriteCommand('favourite', socket, data);
|
||||
SocketPosts.favourite = function(socket, data, callback) {
|
||||
favouriteCommand('favourite', 'favourited', socket, data, callback);
|
||||
sendNotificationToPostOwner(data, socket.uid, 'has favourited your post');
|
||||
};
|
||||
|
||||
SocketPosts.unfavourite = function(socket, data) {
|
||||
favouriteCommand('unfavourite', socket, data);
|
||||
SocketPosts.unfavourite = function(socket, data, callback) {
|
||||
favouriteCommand('unfavourite', 'favourited', socket, data, callback);
|
||||
};
|
||||
|
||||
function favouriteCommand(command, socket, data) {
|
||||
function favouriteCommand(command, eventName, socket, data, callback) {
|
||||
|
||||
if(data && data.pid && data.room_id) {
|
||||
favourites[command](data.pid, data.room_id, socket.uid, socket);
|
||||
favourites[command](data.pid, socket.uid, function(err, result) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
socket.emit('posts.' + command, data.pid);
|
||||
|
||||
if(data.room_id && result && eventName) {
|
||||
websockets.in(data.room_id).emit('event:' + eventName, result);
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,8 +128,8 @@ SocketPosts.getRawPost = function(socket, pid, callback) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(data.deleted === '1') {
|
||||
return callback(new Error('This post no longer exists'));
|
||||
if(parseInt(data.deleted, 10) === 1) {
|
||||
return callback(new Error('[[error:no-post]]'));
|
||||
}
|
||||
|
||||
callback(null, data.content);
|
||||
@@ -140,7 +152,7 @@ SocketPosts.edit = function(socket, data, callback) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
index.server.sockets.in('topic_' + results.topic.tid).emit('event:post_edited', {
|
||||
websockets.server.sockets.in('topic_' + results.topic.tid).emit('event:post_edited', {
|
||||
pid: data.pid,
|
||||
title: results.topic.title,
|
||||
isMainPost: results.topic.isMainPost,
|
||||
@@ -161,7 +173,7 @@ SocketPosts.restore = function(socket, data, callback) {
|
||||
|
||||
function deleteOrRestore(command, socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
postTools[command](socket.uid, data.pid, function(err) {
|
||||
@@ -172,7 +184,7 @@ function deleteOrRestore(command, socket, data, callback) {
|
||||
module.parent.exports.emitTopicPostStats();
|
||||
|
||||
var eventName = command === 'restore' ? 'event:post_restored' : 'event:post_deleted';
|
||||
index.server.sockets.in('topic_' + data.tid).emit(eventName, {
|
||||
websockets.server.sockets.in('topic_' + data.tid).emit(eventName, {
|
||||
pid: data.pid
|
||||
});
|
||||
|
||||
@@ -235,7 +247,7 @@ SocketPosts.getPidIndex = function(socket, pid, callback) {
|
||||
|
||||
SocketPosts.flag = function(socket, pid, callback) {
|
||||
if (!socket.uid) {
|
||||
return callback(new Error('not-logged-in'));
|
||||
return callback(new Error('[[error:not-logged-in]]'));
|
||||
}
|
||||
|
||||
var message = '',
|
||||
@@ -273,7 +285,7 @@ SocketPosts.flag = function(socket, pid, callback) {
|
||||
|
||||
SocketPosts.loadMoreFavourites = function(socket, data, callback) {
|
||||
if(!data || !data.after) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
var start = parseInt(data.after, 10),
|
||||
@@ -284,7 +296,7 @@ SocketPosts.loadMoreFavourites = function(socket, data, callback) {
|
||||
|
||||
SocketPosts.loadMoreUserPosts = function(socket, data, callback) {
|
||||
if(!data || !data.after || !data.uid) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
var start = parseInt(data.after, 10),
|
||||
@@ -296,7 +308,7 @@ SocketPosts.loadMoreUserPosts = function(socket, data, callback) {
|
||||
|
||||
SocketPosts.getRecentPosts = function(socket, data, callback) {
|
||||
if(!data || !data.count) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
posts.getRecentPosts(socket.uid, 0, data.count - 1, data.term, callback);
|
||||
|
||||
@@ -60,7 +60,7 @@ SocketUser.changePassword = function(socket, data, callback) {
|
||||
|
||||
SocketUser.updateProfile = function(socket, data, callback) {
|
||||
if(!data || !data.uid) {
|
||||
return callback(new Error('invalid-data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
if(socket.uid === parseInt(data.uid, 10)) {
|
||||
@@ -73,7 +73,7 @@ SocketUser.updateProfile = function(socket, data, callback) {
|
||||
}
|
||||
|
||||
if(!isAdmin) {
|
||||
return callback(new Error('not allowed!'));
|
||||
return callback(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
|
||||
user.updateProfile(data.uid, data, callback);
|
||||
@@ -82,7 +82,7 @@ SocketUser.updateProfile = function(socket, data, callback) {
|
||||
|
||||
SocketUser.changePicture = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('invalid-data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
var type = data.type;
|
||||
@@ -117,7 +117,7 @@ SocketUser.changePicture = function(socket, data, callback) {
|
||||
} else if (type === 'uploaded') {
|
||||
type = 'uploadedpicture';
|
||||
} else {
|
||||
return callback(new Error('invalid-image-type'));
|
||||
return callback(new Error('[[error:invalid-image-type]]'));
|
||||
}
|
||||
|
||||
if(socket.uid === parseInt(data.uid, 10)) {
|
||||
@@ -136,7 +136,7 @@ SocketUser.changePicture = function(socket, data, callback) {
|
||||
}
|
||||
|
||||
if(!isAdmin) {
|
||||
return callback(new Error('not-allowed'));
|
||||
return callback(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
|
||||
changePicture(data.uid, callback);
|
||||
@@ -170,7 +170,7 @@ SocketUser.saveSettings = function(socket, data, callback) {
|
||||
SocketUser.getOnlineUsers = function(socket, data, callback) {
|
||||
var returnData = {};
|
||||
if(!data) {
|
||||
return callback(new Error('invalid-data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
function getUserStatus(uid, next) {
|
||||
@@ -202,11 +202,11 @@ SocketUser.getActiveUsers = function(socket, data, callback) {
|
||||
|
||||
SocketUser.loadMore = function(socket, data, callback) {
|
||||
if(!data || !data.set || parseInt(data.after, 10) < 0) {
|
||||
return callback(new Error('invalid-data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
if (!socket.uid && !!parseInt(meta.config.privateUserInfo, 10)) {
|
||||
return callback(new Error('not-allowed'));
|
||||
return callback(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
|
||||
var start = data.after,
|
||||
|
||||
@@ -69,9 +69,9 @@ var winston = require('winston'),
|
||||
}
|
||||
|
||||
if (parseInt(deleted, 10) && isDelete) {
|
||||
return callback(new Error('topic-already-deleted'));
|
||||
return callback(new Error('[[error:topic-already-deleted]]'));
|
||||
} else if (!parseInt(deleted, 10) && !isDelete) {
|
||||
return callback(new Error('topic-already-restored'));
|
||||
return callback(new Error('[[error:topic-already-restored]]'));
|
||||
}
|
||||
|
||||
topics[isDelete ? 'delete' : 'restore'](tid, function(err) {
|
||||
|
||||
@@ -58,7 +58,7 @@ var async = require('async'),
|
||||
Topics.getTopicDataWithUser = function(tid, callback) {
|
||||
Topics.getTopicData(tid, function(err, topic) {
|
||||
if (err || !topic) {
|
||||
return callback(err || new Error('topic doesn\'t exist'));
|
||||
return callback(err || new Error('[[error:no-topic]]'));
|
||||
}
|
||||
|
||||
user.getUserFields(topic.uid, ['username', 'userslug', 'picture'] , function(err, userData) {
|
||||
@@ -101,7 +101,7 @@ var async = require('async'),
|
||||
|
||||
Topics.getTidPage = function(tid, uid, callback) {
|
||||
if(!tid) {
|
||||
return callback(new Error('invalid-tid'));
|
||||
return callback(new Error('[[error:invalid-tid]]'));
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
@@ -270,7 +270,7 @@ var async = require('async'),
|
||||
Topics.getTopicWithPosts = function(tid, uid, start, end, callback) {
|
||||
Topics.getTopicData(tid, function(err, topicData) {
|
||||
if (err || !topicData) {
|
||||
return callback(err || new Error('Topic tid \'' + tid + '\' not found'));
|
||||
return callback(err || new Error('[[error:no-topic]]'));
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
@@ -328,8 +328,8 @@ var async = require('async'),
|
||||
posts.getPostFields(pid, ['pid', 'uid', 'timestamp'], function(err, postData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
} else if(!postData) {
|
||||
return callback(new Error('no-teaser-found'));
|
||||
} else if(!postData || !postData.uid) {
|
||||
return callback(new Error('[[error:no-teaser]]'));
|
||||
}
|
||||
|
||||
user.getUserFields(postData.uid, ['username', 'userslug', 'picture'], function(err, userData) {
|
||||
|
||||
@@ -19,11 +19,11 @@ module.exports = function(Topics) {
|
||||
}
|
||||
|
||||
if(!title) {
|
||||
return callback(new Error('invalid-title'));
|
||||
return callback(new Error('[[error:invalid-title]]'));
|
||||
}
|
||||
|
||||
if(!pids || !pids.length) {
|
||||
return callback(new Error('invalid-pids'));
|
||||
return callback(new Error('[[error:invalid-pid]]'));
|
||||
}
|
||||
|
||||
pids.sort();
|
||||
@@ -71,7 +71,7 @@ module.exports = function(Topics) {
|
||||
Topics.movePostToTopic = function(pid, tid, callback) {
|
||||
threadTools.exists(tid, function(err, exists) {
|
||||
if(err || !exists) {
|
||||
return callback(err || new Error('Topic doesn\'t exist'));
|
||||
return callback(err || new Error('[[error:no-topic]]'));
|
||||
}
|
||||
|
||||
posts.getPostFields(pid, ['deleted', 'tid', 'timestamp'], function(err, postData) {
|
||||
@@ -79,8 +79,8 @@ module.exports = function(Topics) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(!postData) {
|
||||
return callback(new Error('Post doesn\'t exist'));
|
||||
if(!postData || !postData.tid) {
|
||||
return callback(new Error('[[error:no-post]]'));
|
||||
}
|
||||
|
||||
Topics.removePostFromTopic(postData.tid, pid, function(err) {
|
||||
|
||||
@@ -30,7 +30,7 @@ module.exports = function(Topics) {
|
||||
|
||||
var count = parseInt(end, 10) === -1 ? end : end - start + 1;
|
||||
|
||||
db.getSortedSetRevRangeByScore(['topics:recent', '+inf', Date.now() - since, 'LIMIT', start, count], callback);
|
||||
db.getSortedSetRevRangeByScore('topics:recent', start, count, Infinity, Date.now() - since, callback);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
@@ -126,11 +126,11 @@ var bcrypt = require('bcryptjs'),
|
||||
}
|
||||
|
||||
if (parseInt(results.banned, 10) === 1) {
|
||||
return callback(new Error('user-banned'));
|
||||
return callback(new Error('[[error:user-banned]]'));
|
||||
}
|
||||
|
||||
if (!results.exists) {
|
||||
return callback(new Error('invalid-user'));
|
||||
return callback(new Error('[[error:no-user]]'));
|
||||
}
|
||||
|
||||
var lastposttime = results.lastposttime;
|
||||
|
||||
@@ -25,17 +25,17 @@ module.exports = function(User) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
if (userData.email) {
|
||||
next(!utils.isEmailValid(userData.email) ? new Error('Invalid Email!') : null);
|
||||
next(!utils.isEmailValid(userData.email) ? new Error('[[error:invalid-email]]') : null);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
next((!utils.isUserNameValid(userData.username) || !userData.userslug) ? new Error('Invalid Username!') : null);
|
||||
next((!utils.isUserNameValid(userData.username) || !userData.userslug) ? new Error('[[error:invalid-username]]') : null);
|
||||
},
|
||||
function(next) {
|
||||
if (userData.password) {
|
||||
next(!utils.isPasswordValid(userData.password) ? new Error('Invalid Password!') : null);
|
||||
next(!utils.isPasswordValid(userData.password) ? new Error('[[error:invalid-password]]') : null);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
@@ -45,7 +45,7 @@ module.exports = function(User) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
next(exists ? new Error('Username taken!') : null);
|
||||
next(exists ? new Error('[[error:username-taken]]') : null);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
@@ -54,7 +54,7 @@ module.exports = function(User) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
next(!available ? new Error('Email taken!') : null);
|
||||
next(!available ? new Error('[[error:email-taken]]') : null);
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
|
||||
@@ -114,7 +114,7 @@ var async = require('async'),
|
||||
UserNotifications.getDailyUnread = function(uid, callback) {
|
||||
var now = Date.now(),
|
||||
yesterday = now - (1000*60*60*24); // Approximate, can be more or less depending on time changes, makes no difference really.
|
||||
db.getSortedSetRangeByScore(['uid:' + uid + ':notifications:unread', yesterday, now], function(err, nids) {
|
||||
db.getSortedSetRangeByScore('uid:' + uid + ':notifications:unread', 0, 20, yesterday, now, function(err, nids) {
|
||||
async.map(nids, function(nid, next) {
|
||||
notifications.get(nid, uid, function(notif_data) {
|
||||
next(null, notif_data);
|
||||
|
||||
@@ -18,7 +18,7 @@ module.exports = function(User) {
|
||||
|
||||
function isSignatureValid(next) {
|
||||
if (data.signature !== undefined && data.signature.length > meta.config.maximumSignatureLength) {
|
||||
next(new Error('Signature can\'t be longer than ' + meta.config.maximumSignatureLength + ' characters!'));
|
||||
next(new Error('[[error:signature-too-long, ' + meta.config.maximumSignatureLength + ']]'));
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
@@ -39,7 +39,7 @@ module.exports = function(User) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
next(!available ? new Error('Email not available!') : null);
|
||||
next(!available ? new Error('[[error:email-taken]]') : null);
|
||||
|
||||
});
|
||||
});
|
||||
@@ -55,7 +55,7 @@ module.exports = function(User) {
|
||||
}
|
||||
|
||||
if(!utils.isUserNameValid(data.username) || !userslug) {
|
||||
return next(new Error('Invalid Username!'));
|
||||
return next(new Error('[[error:invalid-username]]'));
|
||||
}
|
||||
|
||||
User.exists(userslug, function(err, exists) {
|
||||
@@ -63,7 +63,7 @@ module.exports = function(User) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
next(exists ? new Error('Username not available!') : null);
|
||||
next(exists ? new Error('[[error:username-taken]]') : null);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -196,7 +196,7 @@ module.exports = function(User) {
|
||||
|
||||
User.changePassword = function(uid, data, callback) {
|
||||
if(!data || !data.uid) {
|
||||
return callback(new Error('invalid-uid'));
|
||||
return callback(new Error('[[error:invalid-uid]]'));
|
||||
}
|
||||
|
||||
function hashAndSetPassword(callback) {
|
||||
|
||||
@@ -40,7 +40,7 @@ var async = require('async'),
|
||||
UserReset.send = function(socket, email, callback) {
|
||||
user.getUidByEmail(email, function(err, uid) {
|
||||
if(err || !uid) {
|
||||
return callback(err || new Error('invalid-email'));
|
||||
return callback(err || new Error('[[error:invalid-email]]'));
|
||||
}
|
||||
|
||||
// Generate a new reset code
|
||||
|
||||
@@ -37,7 +37,7 @@ module.exports = function(User) {
|
||||
User.saveSettings = function(uid, data, callback) {
|
||||
|
||||
if(!data.topicsPerPage || !data.postsPerPage || parseInt(data.topicsPerPage, 10) <= 0 || parseInt(data.postsPerPage, 10) <= 0) {
|
||||
return callback(new Error('Invalid pagination value!'));
|
||||
return callback(new Error('[[error:invalid-pagination-value]]'));
|
||||
}
|
||||
|
||||
plugins.fireHook('action:user.saveSettings', {uid: uid, settings: data});
|
||||
|
||||
Reference in New Issue
Block a user