"use strict"; var groups = require('../groups'), meta = require('../meta'), plugins = require('../plugins'), user = require('../user'), topics = require('../topics'), categories = require('../categories'), CategoryTools = require('../categoryTools'), logger = require('../logger'), admin = { user: require('../admin/user'), categories: require('../admin/categories') }, async = require('async'), winston = require('winston'), SocketAdmin = {}; SocketAdmin.before = function(sessionData, next) { // Verify administrative privileges user.isAdministrator(sessionData.uid, function(err, isAdmin) { if (isAdmin) { next(); } else { winston.warn('[socket.io] Call to admin method blocked (accessed by uid ' + sessionData.uid + ')'); } }); }; /* Topics */ SocketAdmin.topics = {}; SocketAdmin.topics.getMore = function(data, callback) { topics.getAllTopics(data.limit, data.after, function(err, topics) { callback(JSON.stringify(topics)); }); }; /* User */ SocketAdmin.user = {}; SocketAdmin.user.makeAdmin = function(theirid, sessionData) { if (sessionData.uid && sessionData.uid > 0) { admin.user.makeAdmin(sessionData.uid, theirid, sessionData.socket); } }; SocketAdmin.user.removeAdmin = function(theirid, sessionData) { if (sessionData.uid && sessionData.uid > 0) { admin.user.removeAdmin(sessionData.uid, theirid, sessionData.socket); } }; SocketAdmin.user.createUser = function(user, callback, sessionData) { if (sessionData.uid && sessionData.uid > 0) { admin.user.createUser(sessionData.uid, user, callback); } }; SocketAdmin.user.banUser = function(theirid, sessionData) { if (sessionData.uid && sessionData.uid > 0) { admin.user.banUser(sessionData.uid, theirid, sessionData.socket, function(isBanned) { if(isBanned) { if(sessionData.userSockets[theirid]) { for(var i=0; i