v1.18.x
barisusakli 10 years ago
parent 962d14746e
commit e6973b55d4

@ -23,21 +23,21 @@ var fs = require('fs'),
file = require('../file'), file = require('../file'),
websockets = require('../socket.io'); websockets = require('../socket.io');
function userNotFound(res) { function notFound(res, message) {
res.locals.notFound = true; res.locals.notFound = true;
if (res.locals.isAPI) { if (res.locals.isAPI) {
res.status(404).json('no-user'); res.status(404).json(message);
} else { } else {
res.render('404', { res.render('404', {
error: '[[error:no-user]]' error: message
}); });
} }
} }
function userNotAllowed(res) { function notAllowed(res, message) {
if (res.locals.isAPI) { if (res.locals.isAPI) {
res.status(403).json('not-allowed'); res.status(403).json(message);
} else { } else {
res.render('403'); res.render('403');
} }
@ -169,7 +169,7 @@ accountsController.getAccount = function(req, res, next) {
} }
if(!userData) { if(!userData) {
return userNotFound(res); return notFound(res, '[[error:no-user]]');
} }
async.parallel({ async.parallel({
@ -227,7 +227,7 @@ function getFollow(route, name, req, res, next) {
function(data, next) { function(data, next) {
userData = data; userData = data;
if (!userData) { if (!userData) {
return userNotFound(res); return notFound(res, '[[error:no-user]]');
} }
var method = name === 'following' ? 'getFollowing' : 'getFollowers'; var method = name === 'following' ? 'getFollowing' : 'getFollowers';
user[method](userData.uid, next); user[method](userData.uid, next);
@ -252,11 +252,11 @@ accountsController.getFavourites = function(req, res, next) {
} }
if (!userData) { if (!userData) {
return userNotFound(res); return notFound(res, '[[error:no-user]]');
} }
if (parseInt(userData.uid, 10) !== callerUID) { if (parseInt(userData.uid, 10) !== callerUID) {
return userNotAllowed(res); return notAllowed(res, '[[error:not-allowed]]');
} }
posts.getFavourites(userData.uid, 0, 9, function (err, favourites) { posts.getFavourites(userData.uid, 0, 9, function (err, favourites) {
@ -281,7 +281,7 @@ accountsController.getPosts = function(req, res, next) {
} }
if (!userData) { if (!userData) {
return userNotFound(res); return notFound(res, '[[error:no-user]]');
} }
posts.getPostsByUid(callerUID, userData.uid, 0, 19, function (err, userPosts) { posts.getPostsByUid(callerUID, userData.uid, 0, 19, function (err, userPosts) {
@ -306,7 +306,7 @@ accountsController.getTopics = function(req, res, next) {
} }
if (!userData) { if (!userData) {
return userNotFound(res); return notFound(res, '[[error:no-user]]');
} }
var set = 'uid:' + userData.uid + ':topics'; var set = 'uid:' + userData.uid + ':topics';
@ -390,7 +390,7 @@ accountsController.accountSettings = function(req, res, next) {
} }
if (!userData) { if (!userData) {
return userNotFound(res); return notFound(res, '[[error:no-user]]');
} }
async.parallel({ async.parallel({
@ -408,7 +408,7 @@ accountsController.accountSettings = function(req, res, next) {
userData.settings = results.settings; userData.settings = results.settings;
userData.languages = results.languages; userData.languages = results.languages;
userData.disableEmailSubscriptions = meta.config.disableEmailSubscriptions !== undefined && parseInt(meta.config.disableEmailSubscriptions, 10) === 1; userData.disableEmailSubscriptions = parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
res.render('account/settings', userData); res.render('account/settings', userData);
}); });
@ -468,7 +468,7 @@ accountsController.uploadPicture = function (req, res, next) {
} }
if (!isAdmin) { if (!isAdmin) {
return userNotAllowed(); return notAllowed(req, '[[error:not-allowed]]');
} }
updateUid = uid; updateUid = uid;
next(); next();
@ -532,6 +532,9 @@ accountsController.getNotifications = function(req, res, next) {
}; };
accountsController.getChats = function(req, res, next) { accountsController.getChats = function(req, res, next) {
if (parseInt(meta.config.disableChat) === 1) {
return notFound(res, '[[error:not-found]]');
}
async.parallel({ async.parallel({
contacts: async.apply(user.getFollowing, req.user.uid), contacts: async.apply(user.getFollowing, req.user.uid),
recentChats: async.apply(messaging.getRecentChats, req.user.uid, 0, 19) recentChats: async.apply(messaging.getRecentChats, req.user.uid, 0, 19)

@ -34,6 +34,7 @@ apiController.getConfig = function(req, res, next) {
config.privateUserInfo = parseInt(meta.config.privateUserInfo, 10) === 1; config.privateUserInfo = parseInt(meta.config.privateUserInfo, 10) === 1;
config.usePagination = parseInt(meta.config.usePagination, 10) === 1; config.usePagination = parseInt(meta.config.usePagination, 10) === 1;
config.disableSocialButtons = parseInt(meta.config.disableSocialButtons, 10) === 1; config.disableSocialButtons = parseInt(meta.config.disableSocialButtons, 10) === 1;
config.disableChat = parseInt(meta.config.disableChat, 10) === 1;
config.maxReconnectionAttempts = meta.config.maxReconnectionAttempts || 5; config.maxReconnectionAttempts = meta.config.maxReconnectionAttempts || 5;
config.reconnectionDelay = meta.config.reconnectionDelay || 200; config.reconnectionDelay = meta.config.reconnectionDelay || 200;
config.websocketAddress = meta.config.websocketAddress || ''; config.websocketAddress = meta.config.websocketAddress || '';

@ -117,10 +117,14 @@ SocketModules.chats.get = function(socket, data, callback) {
}; };
SocketModules.chats.send = function(socket, data, callback) { SocketModules.chats.send = function(socket, data, callback) {
if(!data) { if (!data) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
if (parseInt(meta.config.disableChat) === 1) {
return callback(new Error('[[error:chat-disabled]]'));
}
var touid = parseInt(data.touid, 10); var touid = parseInt(data.touid, 10);
if (touid === socket.uid || socket.uid === 0) { if (touid === socket.uid || socket.uid === 0) {
return; return;

@ -70,6 +70,11 @@
<input type="checkbox" data-field="disableSocialButtons"> <strong>Disable social buttons</strong> <input type="checkbox" data-field="disableSocialButtons"> <strong>Disable social buttons</strong>
</label> </label>
</div> </div>
<div class="checkbox">
<label>
<input type="checkbox" data-field="disableChat"> <strong>Disable chat</strong>
</label>
</div>
</form> </form>
</div> </div>
</div> </div>

Loading…
Cancel
Save