hardlounge/src/command-line/add.js
Daniel 3a2d97af6a Supersede mkdirp with fs-extra.
Ensure USERS_PATH exists at start.

Remove unnecessary USER_PATH check.

Use fs-extra's copy to write default config.
2016-06-11 19:35:40 +01:00

36 lines
866 B
JavaScript

var ClientManager = new require("../clientManager");
var bcrypt = require("bcrypt-nodejs");
var program = require("commander");
var Helper = require("../helper");
program
.command("add <name>")
.description("Add a new user")
.action(function(name/* , password */) {
var manager = new ClientManager();
var users = manager.getUsers();
if (users.indexOf(name) !== -1) {
log.error("User '" + name + "' already exists.");
return;
}
require("read")({
prompt: "[thelounge] Enter password: ",
silent: true
}, function(err, password) {
if (!err) {
add(manager, name, password);
}
});
});
function add(manager, name, password) {
var salt = bcrypt.genSaltSync(8);
var hash = bcrypt.hashSync(password, salt);
manager.addUser(
name,
hash
);
log.info("User '" + name + "' created:");
log.info(Helper.getUserConfigPath(name));
}