diff --git a/src/socket.io/user.js b/src/socket.io/user.js index 81667079b9..88273f8709 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -22,7 +22,12 @@ SocketUser.exists = function(socket, data, callback) { SocketUser.deleteAccount = function(socket, data, callback) { if (socket.uid) { - user.deleteAccount(socket.uid, callback); + user.isAdministrator(socket.uid, function(err, isAdmin) { + if (err || isAdmin) { + return callback(err || new Error('[[error:cant-delete-admin]]')); + } + user.deleteAccount(socket.uid, callback); + }); } }; diff --git a/src/user/delete.js b/src/user/delete.js index ac4ba1251d..8c34fe6542 100644 --- a/src/user/delete.js +++ b/src/user/delete.js @@ -25,16 +25,6 @@ module.exports = function(User) { ], callback); }; - User.deleteAccount = function(uid, callback) { - user.isAdministrator(uid, function(err, isAdmin) { - if (err || isAdmin) { - return callback(err || new Error('[[error:cant-ban-other-admins]]')); - } - - deleteAccount(uid, callback); - }); - }; - function deletePosts(uid, callback) { deleteSortedSetElements('uid:' + uid + ':posts', posts.purge, callback); } @@ -53,7 +43,7 @@ module.exports = function(User) { }, {alwaysStartAt: 0}, callback); } - function deleteAccount(uid, callback) { + User.deleteAccount = function(uid, callback) { user.getUserFields(uid, ['username', 'userslug', 'email'], function(err, userData) { if (err) { return callback(err); @@ -107,7 +97,7 @@ module.exports = function(User) { ], callback); }); }); - } + }; function deleteUserFromFollowers(uid, callback) { db.getSetMembers('followers:' + uid, function(err, uids) {