From a802dc4b68eda3bbc281072b36e83de7d12ac787 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 17 Jan 2014 12:42:19 -0500 Subject: [PATCH] admin.js socket fixes --- public/src/forum/admin/categories.js | 40 +++++---- public/src/forum/admin/groups.js | 7 +- public/src/forum/admin/themes.js | 6 +- public/src/forum/admin/topics.js | 7 +- public/src/forum/admin/users.js | 17 ++-- src/admin/user.js | 7 +- src/meta.js | 2 +- src/socket.io/admin.js | 117 ++++++++++++++++++--------- 8 files changed, 140 insertions(+), 63 deletions(-) diff --git a/public/src/forum/admin/categories.js b/public/src/forum/admin/categories.js index 8f2a18c69b..327e29968f 100644 --- a/public/src/forum/admin/categories.js +++ b/public/src/forum/admin/categories.js @@ -87,22 +87,25 @@ define(['uploader'], function(uploader) { }; socket.emit('admin.categories.create', category, function(err, data) { - if (!err) { - app.alert({ - alert_id: 'category_created', - title: 'Created', - message: 'Category successfully created!', - type: 'success', - timeout: 2000 - }); - - var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({ - categories: [data] - }); - $('#entry-container').append(html); - - $('#new-category-modal').modal('hide'); + if(err) { + return app.alertError(err.message); } + + app.alert({ + alert_id: 'category_created', + title: 'Created', + message: 'Category successfully created!', + type: 'success', + timeout: 2000 + }); + + var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({ + categories: [data] + }); + + $('#entry-container').append(html); + $('#new-category-modal').modal('hide'); + }); } @@ -227,6 +230,10 @@ define(['uploader'], function(uploader) { username: searchEl.value, cid: cid }, function(err, results) { + if(err) { + return app.alertError(err.message); + } + var numResults = results.length, resultObj; for(var x=0;x 0) { var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({ topics: topics diff --git a/public/src/forum/admin/users.js b/public/src/forum/admin/users.js index 802431735c..e890329118 100644 --- a/public/src/forum/admin/users.js +++ b/public/src/forum/admin/users.js @@ -126,16 +126,19 @@ define(function() { } function handleUserCreate() { + var errorEl = $('#create-modal-error'); $('#createUser').on('click', function() { $('#create-modal').modal('show'); + $('#create-modal form')[0].reset(); + errorEl.addClass('hide'); }); $('#create-modal-go').on('click', function() { var username = $('#create-user-name').val(), email = $('#create-user-email').val(), password = $('#create-user-password').val(), - passwordAgain = $('#create-user-password-again').val(), - errorEl = $('#create-modal-error'); + passwordAgain = $('#create-user-password-again').val(); + if(password !== passwordAgain) { return errorEl.html('Error

Passwords must match!

').removeClass('hide'); @@ -147,13 +150,15 @@ define(function() { password: password }; - socket.emit('admin.user.createUser', user, function(err, data) { + socket.emit('admin.user.createUser', user, function(err) { if(err) { - return errorEl.html('Error

' + err + '

').removeClass('hide'); + return errorEl.html('Error

' + err.message + '

').removeClass('hide'); } $('#create-modal').modal('hide'); + $('#create-modal').on('hidden.bs.modal', function() { + ajaxify.go('admin/users'); + }); app.alertSuccess('User created!'); - ajaxify.go('admin/users'); }); }); @@ -191,7 +196,7 @@ define(function() { socket.emit('admin.user.search', username, function(err, data) { if(err) { return app.alertError(err.message); - } + }console.log(data) var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ users: data diff --git a/src/admin/user.js b/src/admin/user.js index 1c9453b9fb..f295f78916 100644 --- a/src/admin/user.js +++ b/src/admin/user.js @@ -6,11 +6,16 @@ var utils = require('../../public/src/utils'), UserAdmin.createUser = function(uid, userData, callback) { user.isAdministrator(uid, function(err, isAdmin) { + if(err) { + return callback(err); + } + if (isAdmin) { user.create(userData.username, userData.password, userData.email, function(err) { if(err) { - return callback(err.message); + return callback(err); } + callback(null); }); } else { diff --git a/src/meta.js b/src/meta.js index 8af0917d8c..1eec18351e 100644 --- a/src/meta.js +++ b/src/meta.js @@ -122,7 +122,7 @@ var fs = require('fs'), 'theme:templates': '', 'theme:src': '' }; - +console.log(themeData); switch(data.type) { case 'local': async.waterfall([ diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index 7395ec800a..320f0d4a64 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -35,9 +35,11 @@ SocketAdmin.before = function(socket, next) { SocketAdmin.topics = {}; SocketAdmin.topics.getMore = function(socket, data, callback) { - topics.getAllTopics(data.limit, data.after, function(err, topics) { - callback(JSON.stringify(topics)); - }); + if(!data) { + return callback(new Error('invalid data')); + } + + topics.getAllTopics(data.limit, data.after, callback); }; /* User */ @@ -53,15 +55,18 @@ SocketAdmin.user.removeAdmin = function(socket, theirid) { }; SocketAdmin.user.createUser = function(socket, user, callback) { + if(!user) { + return callback(new Error('invalid data')); + } admin.user.createUser(socket.uid, user, callback); }; SocketAdmin.user.banUser = function(socket, theirid) { admin.user.banUser(socket.uid, theirid, socket, function(isBanned) { if(isBanned) { - if(socket.userSockets[theirid]) { - for(var i=0; i