diff --git a/public/src/forum/admin/footer.js b/public/src/forum/admin/footer.js index 8a99da7a74..f992abc9c6 100644 --- a/public/src/forum/admin/footer.js +++ b/public/src/forum/admin/footer.js @@ -15,28 +15,6 @@ jQuery('document').ready(function() { }, false); }); -socket.once('api:config.get', function(config) { +socket.emit('api:meta.config.get', function(config) { app.config = config; }); - -socket.emit('api:config.get'); - -socket.on('api:config.set', function(data) { - if (data.status === 'ok') { - app.alert({ - alert_id: 'config_status', - timeout: 2500, - title: 'Changes Saved', - message: 'Your changes to the NodeBB configuration have been saved.', - type: 'success' - }); - } else { - app.alert({ - alert_id: 'config_status', - timeout: 2500, - title: 'Changes Not Saved', - message: 'NodeBB encountered a problem saving your changes', - type: 'danger' - }); - } -}); \ No newline at end of file diff --git a/public/src/forum/admin/index.js b/public/src/forum/admin/index.js index 96acb81c46..92bfbe2f2c 100644 --- a/public/src/forum/admin/index.js +++ b/public/src/forum/admin/index.js @@ -3,7 +3,9 @@ define(function() { Admin.init = function() { ajaxify.register_events(['api:get_all_rooms']); - socket.on('api:get_all_rooms', function(data) { + + app.enterRoom('admin'); + socket.emit('api:meta.rooms.getAll', function(data) { var active_users = document.getElementById('active_users'), total = 0; @@ -20,9 +22,6 @@ define(function() { document.getElementById('connections').innerHTML = total; }); - app.enterRoom('admin'); - socket.emit('api:get_all_rooms'); - $('#logout-link').on('click', function() { $.post(RELATIVE_PATH + '/logout', { _csrf: $('#csrf_token').val() diff --git a/public/src/forum/admin/settings.js b/public/src/forum/admin/settings.js index 95cc3c1b9b..aa2ec727e4 100644 --- a/public/src/forum/admin/settings.js +++ b/public/src/forum/admin/settings.js @@ -67,9 +67,27 @@ define(['uploader'], function(uploader) { value = fields[x].value; } - socket.emit('api:config.set', { + socket.emit('api:meta.config.set', { key: key, value: value + }, function(data) { + if (data.status === 'ok') { + app.alert({ + alert_id: 'config_status', + timeout: 2500, + title: 'Changes Saved', + message: 'Your changes to the NodeBB configuration have been saved.', + type: 'success' + }); + } else { + app.alert({ + alert_id: 'config_status', + timeout: 2500, + title: 'Changes Not Saved', + message: 'NodeBB encountered a problem saving your changes', + type: 'danger' + }); + } }); } }); @@ -98,7 +116,7 @@ define(['uploader'], function(uploader) { }; Settings.remove = function(key) { - socket.emit('api:config.remove', key); + socket.emit('api:meta.config.remove', key); }; return Settings; diff --git a/public/templates/install/basic.tpl b/public/templates/install/basic.tpl deleted file mode 100644 index 5c3936cefa..0000000000 --- a/public/templates/install/basic.tpl +++ /dev/null @@ -1,51 +0,0 @@ - -

Step 2 – Basic Information

- -
-

Path Information

-

- Please enter the web-accessible url that will be used to point to the NodeBB installation. If you are using a port number in the address, - include it in the field below, not here. Do not include a trailing slash.
- -

- -

- -

-

- -

- -

- Path to uploads folder (relative to the root of the NodeBB install)
- -

-
- -

NodeBB Secret

-

- This "secret" is used to encode user sessions, so they are not stored in plaintext. Enter a bunch of random characters below: -

- - -
-
- -
-
- -
- - \ No newline at end of file diff --git a/public/templates/install/footer.tpl b/public/templates/install/footer.tpl deleted file mode 100644 index 8fc558d4c8..0000000000 --- a/public/templates/install/footer.tpl +++ /dev/null @@ -1,143 +0,0 @@ - - - - \ No newline at end of file diff --git a/public/templates/install/header.tpl b/public/templates/install/header.tpl deleted file mode 100644 index 5cae4b5e03..0000000000 --- a/public/templates/install/header.tpl +++ /dev/null @@ -1,52 +0,0 @@ - - - - NodeBB - - - - - - - - - - - - - - - - - - - - - -
- -
\ No newline at end of file diff --git a/public/templates/install/mail.tpl b/public/templates/install/mail.tpl deleted file mode 100644 index 070c03d111..0000000000 --- a/public/templates/install/mail.tpl +++ /dev/null @@ -1,33 +0,0 @@ - -

Mailer Information

- -
-

- The mailer information is used when sending out registration confirmation emails to new users. - It is also used to send password reset emails to users who have forgotten their password. -

-

- The defaults here correspond to a local sendmail server, although any third-party - mail server can be used. -

-

- -

-

- -

-

- -

-
- -
-
- -
- - \ No newline at end of file diff --git a/public/templates/install/privileges.tpl b/public/templates/install/privileges.tpl deleted file mode 100644 index c54f7cf7f7..0000000000 --- a/public/templates/install/privileges.tpl +++ /dev/null @@ -1,45 +0,0 @@ -

User Privilege Thresholds

- -
-

- Privilege thresholds grants a community membership the ability to moderate itself. - These numbers denote the minimum amount of user reputation required before the - corresponding privilege is unlocked. -

-

- Reputation is gained when other users favourite posts that you have made. -

- -

- -

-

- Users who reach the "Manage Content" threshold are able to edit/delete other users' posts. -

-

- -

-

- Users who reach the "Manage Topics" threshold are able to edit, lock, pin, close, and delete topics. -

-
- -
-
- -
-
- -
- - diff --git a/public/templates/install/redis.tpl b/public/templates/install/redis.tpl deleted file mode 100644 index 5fa4d2a828..0000000000 --- a/public/templates/install/redis.tpl +++ /dev/null @@ -1,81 +0,0 @@ - -

Step 1 – Establish Redis Connection

- -

- Thanks for choosing to install NodeBB! We'll need some information to set up your installation - configuration... -

-

- Please enter the details of your Redis server here. If redis is hosted on the same - server as NodeBB, you can leave the default values as-is. -

- -
-
- -
- -
-
-
- -
- -
-
-
-
- -
-
-
- -
-
- -
- - diff --git a/public/templates/install/social.tpl b/public/templates/install/social.tpl deleted file mode 100644 index 6179ca1f35..0000000000 --- a/public/templates/install/social.tpl +++ /dev/null @@ -1,47 +0,0 @@ - -

Social Media Logins

- -
-

- You may opt to allow users to register and login in via a social media account, if that - social network supports doing so. -

- -

Facebook

-

- -

-

- -

- -

Twitter

-

- -

-

- -

- -

Google

-

- -

-

- -

-
- -
-
- -
-
- -
- - \ No newline at end of file diff --git a/src/admin/user.js b/src/admin/user.js index 8e754ab1a4..1c9453b9fb 100644 --- a/src/admin/user.js +++ b/src/admin/user.js @@ -72,6 +72,7 @@ var utils = require('../../public/src/utils'), user.ban(theirid, function(err, result) { callback(true); socket.emit('event:alert', { + alert_id: 'ban_user', title: 'User Banned', message: 'This user is banned!', type: 'success', @@ -88,6 +89,7 @@ var utils = require('../../public/src/utils'), if (amIAdmin) { user.unban(theirid, function(err, result) { socket.emit('event:alert', { + alert_id: 'ban_user', title: 'User Unbanned', message: 'This user is unbanned!', type: 'success', diff --git a/src/socket.io/index.js b/src/socket.io/index.js index a814d743bf..5723465c25 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -150,7 +150,8 @@ Sockets.init = function() { uid: uid, socket: socket, rooms: rooms, - server: io + server: io, + userSockets: userSockets }, socketArgs = []; diff --git a/src/socket.io/meta.js b/src/socket.io/meta.js index d774a02a18..732dc072ff 100644 --- a/src/socket.io/meta.js +++ b/src/socket.io/meta.js @@ -1,6 +1,9 @@ var meta = require('../meta'), user = require('../user'), + logger = require('../logger'), + plugins = require('../plugins'), + nconf = require('nconf'), gravatar = require('gravatar'), SocketMeta = {}; @@ -69,6 +72,43 @@ SocketMeta.rooms.enter = function(data, sessionData) { } }; +SocketMeta.rooms.getAll = function(callback, sessionData) { + callback(sessionData.server.sockets.manager.rooms); +}; + +/* Config */ + +SocketMeta.config = {}; + +SocketMeta.config.get = function(callback, sessionData) { + meta.configs.list(function(err, config) { + if (!err) { + callback(config); + } + }); +}; + +SocketMeta.config.set = function(data, callback, sessionData) { + meta.configs.set(data.key, data.value, function(err) { + if (!err) { + callback({ + status: 'ok' + }); + + plugins.fireHook('action:config.set', { + key: data.key, + value: data.value + }); + } + + logger.monitorConfig({io: sessionData.server}, data); + }); +}; + +SocketMeta.config.remove = function(key) { + meta.configs.remove(key); +}; + /* Exports */ module.exports = SocketMeta; \ No newline at end of file diff --git a/src/websockets.js b/src/websockets.js index 1f0fe0fcc6..a7f8e82025 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -35,9 +35,7 @@ var cookie = require('cookie'), websockets.init = function(io) { - socket.on('api:get_all_rooms', function(data) { - socket.emit('api:get_all_rooms', io.sockets.manager.rooms); - }); + @@ -299,32 +297,7 @@ websockets.init = function(io) { }); }); - socket.on('api:config.get', function(data) { - meta.configs.list(function(err, config) { - if (!err) socket.emit('api:config.get', config); - }); - }); - - socket.on('api:config.set', function(data) { - meta.configs.set(data.key, data.value, function(err) { - if (!err) { - socket.emit('api:config.set', { - status: 'ok' - }); - - plugins.fireHook('action:config.set', { - key: data.key, - value: data.value - }); - } - logger.monitorConfig({io: io}, data); - }); - }); - - socket.on('api:config.remove', function(key) { - meta.configs.remove(key); - }); socket.on('api:composer.push', function(data, callback) { @@ -389,193 +362,7 @@ websockets.init = function(io) { }); }); - socket.on('api:admin.topics.getMore', function(data, callback) { - topics.getAllTopics(data.limit, data.after, function(err, topics) { - callback(JSON.stringify(topics)); - }); - }); - - socket.on('api:admin.categories.create', function(data, callback) { - categories.create(data, function(err, data) { - callback(err, data); - }); - }); - - socket.on('api:admin.categories.update', function(data) { - admin.categories.update(data, socket); - }); - - socket.on('api:admin.user.makeAdmin', function(theirid) { - if (uid && uid > 0) { - admin.user.makeAdmin(uid, theirid, socket); - } - }); - - socket.on('api:admin.user.removeAdmin', function(theirid) { - if (uid && uid > 0) { - admin.user.removeAdmin(uid, theirid, socket); - } - }); - - socket.on('api:admin.user.createUser', function(user, callback) { - if (uid && uid > 0) { - admin.user.createUser(uid, user, callback); - } - }); - - socket.on('api:admin.user.banUser', function(theirid) { - if (uid && uid > 0) { - admin.user.banUser(uid, theirid, socket, function(isBanned) { - if(isBanned) { - if(userSockets[theirid]) { - for(var i=0; i 0) { - admin.user.unbanUser(uid, theirid, socket); - } - }); - - socket.on('api:admin.user.search', function(username, callback) { - if (!(uid && uid > 0)) { - return callback(); - } - - user.search(username, function(data) { - function isAdmin(userData, next) { - user.isAdministrator(userData.uid, function(err, isAdmin) { - if(err) { - return next(err); - } - - userData.administrator = isAdmin?'1':'0'; - next(); - }); - } - async.each(data, isAdmin, function(err) { - if(err) { - return callback({message: err.message}); - } - - callback(null, data); - }); - }); - }); - - socket.on('api:admin.categories.search', function(username, cid, callback) { - if (uid && uid > 0) { - user.search(username, function(data) { - async.map(data, function(userObj, next) { - CategoryTools.privileges(cid, userObj.uid, function(err, privileges) { - if (!err) { - userObj.privileges = privileges; - } else { - winston.error('[socket api:admin.categories.search] Could not retrieve permissions'); - } - - next(null, userObj); - }); - }, function(err, data) { - if (!callback) socket.emit('api:admin.categories.search', data); - else callback(null, data); - }); - }); - } else { - if (!callback) socket.emit('api:admin.user.search', null); - else callback(); - } - }); - - socket.on('api:admin.categories.setPrivilege', function(cid, uid, privilege, set, callback) { - var cb = function(err) { - CategoryTools.privileges(cid, uid, callback); - }; - - if (set) { - groups.joinByGroupName('cid:' + cid + ':privileges:' + privilege, uid, cb); - } else { - groups.leaveByGroupName('cid:' + cid + ':privileges:' + privilege, uid, cb); - } - }); - - socket.on('api:admin.categories.getPrivilegeSettings', function(cid, callback) { - async.parallel({ - "+r": function(next) { - groups.getByGroupName('cid:' + cid + ':privileges:+r', { expand: true }, function(err, groupObj) { - if (!err) { - next.apply(this, arguments); - } else { - next(null, { - members: [] - }); - } - }); - }, - "+w": function(next) { - groups.getByGroupName('cid:' + cid + ':privileges:+w', { expand: true }, function(err, groupObj) { - if (!err) { - next.apply(this, arguments); - } else { - next(null, { - members: [] - }); - } - }); - } - }, function(err, data) { - callback(null, { - "+r": data['+r'].members, - "+w": data['+w'].members - }); - }); - }); - - socket.on('api:admin.categories.setGroupPrivilege', function(cid, gid, privilege, set, callback) { - if (set) { - groups.joinByGroupName('cid:' + cid + ':privileges:' + privilege, gid, callback); - } else { - groups.leaveByGroupName('cid:' + cid + ':privileges:' + privilege, gid, callback); - } - }); - - socket.on('api:admin.categories.groupsList', function(cid, callback) { - groups.list({expand:false}, function(err, data){ - async.map(data, function(groupObj, next) { - CategoryTools.groupPrivileges(cid, groupObj.gid, function(err, privileges) { - if (!err) { - groupObj.privileges = privileges; - } else { - winston.error('[socket api:admin.categories.groupsList] Could not retrieve permissions'); - } - - next(null, groupObj); - }); - }, function(err, data) { - callback(null, data); - }); - }); - }); - - socket.on('api:admin.themes.getInstalled', function(callback) { - meta.themes.get(function(err, themeArr) { - callback(themeArr); - }); - }); - - socket.on('api:admin.plugins.toggle', function(plugin_id) { - plugins.toggleActive(plugin_id, function(status) { - socket.emit('api:admin.plugins.toggle', status); - }); - });