fixes to administrator methods

v1.18.x
Julian Lam 12 years ago
parent 780cec2596
commit ce126b11fb

@ -1,22 +1,28 @@
var RDB = require('./../redis.js'),
utils = require('./../../public/src/utils.js'),
user = require('./../user.js');
var RDB = require('../redis'),
utils = require('../../public/src/utils'),
user = require('../user'),
Groups = require('../groups');
(function(UserAdmin) {
UserAdmin.makeAdmin = function(uid, theirid, socket) {
user.isAdministrator(uid, function(isAdmin) {
if(isAdmin) {
user.makeAdministrator(theirid, function(data) {
socket.emit('event:alert', {
title: 'User Modified',
message: 'This user is now an administrator!',
type: 'success',
timeout: 2000
});
Groups.getGidFromName('Administrators', function(err, gid) {
Groups.join(gid, theirid, function(err) {
if (!err) {
user.setUserField(theirid, 'administrator', 1);
socket.emit('event:alert', {
title: 'User Modified',
message: 'This user is now an administrator!',
type: 'success',
timeout: 2000
});
}
});
});
}
else {
} else {
socket.emit('event:alert', {
title: 'Warning',
message: 'You need to be an administrator to make someone else an administrator!',
@ -30,13 +36,18 @@ var RDB = require('./../redis.js'),
UserAdmin.removeAdmin = function(uid, theirid, socket) {
user.isAdministrator(uid, function(isAdmin) {
if(isAdmin) {
user.removeAdministrator(theirid, function(data) {
Groups.getGidFromName('Administrators', function(err, gid) {
Groups.leave(gid, theirid, function(err) {
if (!err) {
user.setUserField(theirid, 'administrator', 0);
socket.emit('event:alert', {
title: 'User Modified',
message: 'This user is no longer an administrator!',
type: 'success',
timeout: 2000
socket.emit('event:alert', {
title: 'User Modified',
message: 'This user is no longer an administrator!',
type: 'success',
timeout: 2000
});
}
});
});
}

@ -192,23 +192,31 @@ var async = require('async'),
hidden: true,
type: 'string'
}
];
prompt.get(questions, function(err, results) {
if (!results) return callback(new Error('aborted'));
nconf.set('bcrypt_rounds', 12);
User.create(results.username, results.password, results.email, function(err, uid) {
Groups.getGidFromName('Administrators', function(err, gid) {
if (gid) Groups.join(gid, uid, callback);
else {
Groups.create('Administrators', 'Forum Administrators', function(err, groupObj) {
Groups.join(groupObj.gid, uid, callback);
],
getAdminInfo = function(callback) {
prompt.get(questions, function(err, results) {
if (!results) return callback(new Error('aborted'));
nconf.set('bcrypt_rounds', 12);
User.create(results.username, results.password, results.email, function(err, uid) {
if (err) {
winston.warn(err.message + ' Please try again.');
return getAdminInfo();
}
Groups.getGidFromName('Administrators', function(err, gid) {
if (gid) Groups.join(gid, uid, callback);
else {
Groups.create('Administrators', 'Forum Administrators', function(err, groupObj) {
Groups.join(groupObj.gid, uid, callback);
});
}
});
}
});
});
});
});
};
getAdminInfo(callback);
},
save: function(server_conf, client_conf, callback) {
// Server Config

@ -5,6 +5,7 @@ var utils = require('./../public/src/utils.js'),
meta = require('./meta.js'),
emailjsServer = emailjs.server.connect(meta.config.mailer || '127.0.0.1'),
bcrypt = require('bcrypt'),
Groups = require('./groups'),
notifications = require('./notifications.js'),
topics = require('./topics.js'),
async = require('async'),
@ -769,35 +770,10 @@ var utils = require('./../public/src/utils.js'),
}
User.isAdministrator = function(uid, callback) {
RDB.sismember('administrators', uid, function(err, exists) {
RDB.handle(err);
callback(!!exists);
});
}
User.makeAdministrator = function(uid, callback) {
RDB.sadd('administrators', uid, function(err, data){
if(!err) {
User.setUserField(uid, 'administrator', 1);
}
if(callback) {
// @todo address why we're only sending back a boolean in the callback and not an error if it occurred
callback(err === null);
}
});
}
User.removeAdministrator = function(uid, callback) {
RDB.srem('administrators', uid, function(err, data){
if(!err) {
User.setUserField(uid, 'administrator', 0);
}
if(callback) {
// @todo address why we're only sending back a boolean in the callback and not an error if it occurred
callback(err === null);
}
Groups.getGidFromName('Administrators', function(err, gid) {
Groups.isMember(uid, gid, function(err, isAdmin) {
callback(isAdmin);
});
});
}

Loading…
Cancel
Save