forked from openhab/openhab-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeadmin.js
36 lines (31 loc) · 1006 Bytes
/
makeadmin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// This is a small CLI utility to make a user member of staff
var mongoose = require('mongoose'),
logger = require('./logger.js'),
config = require('./config.json'),
User = require('./models/user'),
system = require('./system'),
MongoConnect = require('./system/mongoconnect'),
mongoConnect;
system.setConfiguration(config);
mongoConnect = new MongoConnect(system);
mongoConnect.connect(mongoose);
username = process.argv[2];
if (!username) {
console.log('Usage: node makeadmin.js <username>');
process.exit(0);
}
User.findOne({username: username}, function(error, user) {
if (!error && user) {
console.log('Found ' + username + 'user, making him staff');
user.group = 'staff';
user.save(function(error) {
process.exit(0);
});
} else if (!user) {
console.log('User ' + username + ' not found!');
process.exit(0);
} else {
console.log('Error: ' + error);
process.exit(0);
}
});