mirror of
https://github.com/thelounge/thelounge
synced 2024-11-26 22:10:22 +00:00
Update 'add' command
This commit is contained in:
parent
78d36d6750
commit
c3552319cd
1 changed files with 23 additions and 18 deletions
|
@ -6,9 +6,9 @@ var mkdirp = require("mkdirp");
|
|||
var Helper = require("../helper");
|
||||
|
||||
program
|
||||
.command("add <name>")
|
||||
.command("add <name> [<password>]")
|
||||
.description("Add a new user")
|
||||
.action(function(name) {
|
||||
.action(function(name, password) {
|
||||
var path = Helper.resolveHomePath("users");
|
||||
try {
|
||||
mkdirp.sync(path);
|
||||
|
@ -38,20 +38,25 @@ program
|
|||
console.log("");
|
||||
return;
|
||||
}
|
||||
require("read")({
|
||||
prompt: "Password: ",
|
||||
silent: true
|
||||
}, function(err, password) {
|
||||
console.log("");
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
var hash = bcrypt.hashSync(password, 8);
|
||||
manager.addUser(
|
||||
name,
|
||||
hash
|
||||
);
|
||||
console.log("Added '" + name + "'.");
|
||||
console.log("");
|
||||
});
|
||||
if (password) {
|
||||
add(manager, name, password);
|
||||
} else {
|
||||
require("read")({
|
||||
prompt: "Password: ",
|
||||
silent: true
|
||||
}, function(err, password) {
|
||||
if (!err) add(manager, name, password);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function add(manager, name, password) {
|
||||
console.log("");
|
||||
var hash = bcrypt.hashSync(password, 8);
|
||||
manager.addUser(
|
||||
name,
|
||||
hash
|
||||
);
|
||||
console.log("Added '" + name + "'.");
|
||||
console.log("");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue