2014-08-18 21:18:40 -04:00
|
|
|
var ClientManager = new require("../clientManager");
|
|
|
|
var fs = require("fs");
|
|
|
|
var program = require("commander");
|
2014-09-09 04:09:54 -04:00
|
|
|
var mkdirp = require("mkdirp");
|
2014-08-18 21:18:40 -04:00
|
|
|
|
2014-08-26 14:00:12 -04:00
|
|
|
const HOME = process.env.HOME + "/.shout";
|
|
|
|
|
2014-08-18 21:18:40 -04:00
|
|
|
program
|
|
|
|
.command("add <name>")
|
|
|
|
.description("Add a new user")
|
|
|
|
.action(function(name) {
|
2014-09-09 04:09:54 -04:00
|
|
|
try {
|
|
|
|
var path = HOME + "/users";
|
|
|
|
mkdirp.sync(path);
|
|
|
|
} catch (e) {
|
|
|
|
console.log("");
|
|
|
|
console.log("Could not create " + path);
|
|
|
|
console.log("Try running the command as sudo.");
|
|
|
|
console.log("");
|
|
|
|
return;
|
|
|
|
}
|
2014-08-18 21:18:40 -04:00
|
|
|
try {
|
2014-08-26 14:00:12 -04:00
|
|
|
var path = HOME + "/users";
|
2014-08-18 21:18:40 -04:00
|
|
|
var test = path + "/.test";
|
|
|
|
fs.mkdirSync(test);
|
|
|
|
fs.rmdirSync(test);
|
|
|
|
} catch (e) {
|
|
|
|
console.log("");
|
|
|
|
console.log("You have no permissions to write to " + path);
|
|
|
|
console.log("Try running the command as sudo.");
|
|
|
|
console.log("");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var manager = new ClientManager();
|
|
|
|
var users = manager.getUsers();
|
|
|
|
if (users.indexOf(name) !== -1) {
|
|
|
|
console.log("");
|
|
|
|
console.log("User '" + name + "' already exists.");
|
|
|
|
console.log("");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
require("read")({
|
|
|
|
prompt: "Password: "
|
|
|
|
}, function(err, password) {
|
|
|
|
console.log("");
|
|
|
|
if (err) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var success = manager.addUser(
|
|
|
|
name,
|
|
|
|
password
|
|
|
|
);
|
|
|
|
console.log("Added '" + name + "'.");
|
|
|
|
console.log("");
|
|
|
|
});
|
|
|
|
});
|