hardlounge/src/command-line/add.js

40 lines
887 B
JavaScript
Raw Normal View History

"use strict";
2014-09-13 21:29:45 +00:00
var ClientManager = new require("../clientManager");
var program = require("commander");
2014-09-13 21:55:07 +00:00
var Helper = require("../helper");
2014-09-13 21:29:45 +00:00
program
.command("add <name>")
2014-09-13 21:29:45 +00:00
.description("Add a new user")
2015-09-30 22:39:57 +00:00
.action(function(name/* , password */) {
2014-09-13 21:29:45 +00:00
var manager = new ClientManager();
var users = manager.getUsers();
if (users.indexOf(name) !== -1) {
2016-04-16 11:32:38 +00:00
log.error("User '" + name + "' already exists.");
2014-09-13 21:29:45 +00:00
return;
}
require("read")({
prompt: "[thelounge] Enter password: ",
silent: true
}, function(err, password) {
if (!password) {
log.error("Password cannot be empty.");
return;
}
if (!err) {
add(manager, name, password);
}
});
2014-09-13 21:29:45 +00:00
});
2014-09-15 21:31:25 +00:00
2014-09-16 17:33:15 +00:00
function add(manager, name, password) {
2016-10-21 19:00:43 +00:00
var hash = Helper.password.hash(password);
2014-10-14 20:53:26 +00:00
manager.addUser(
2014-09-16 17:33:15 +00:00
name,
hash
);
2016-04-16 11:32:38 +00:00
log.info("User '" + name + "' created:");
log.info(Helper.getUserConfigPath(name));
2014-09-16 17:33:15 +00:00
}