hardlounge/src/command-line/reset.js

39 lines
971 B
JavaScript
Raw Normal View History

2014-09-11 21:00:08 +00:00
var bcrypt = require("bcrypt");
var ClientManager = new require("../clientManager");
var fs = require("fs");
var program = require("commander");
var Helper = require("../helper");
2014-09-11 21:00:08 +00:00
program
.command("reset <name>")
.description("Reset user password")
.action(function(name) {
var users = new ClientManager().getUsers();
if (users.indexOf(name) === -1) {
console.log("");
console.log("User '" + name + "' doesn't exist.");
console.log("");
return;
}
var path = Helper.resolveHomePath("users");
2014-09-11 21:00:08 +00:00
var file = path + name + "/user.json";
var user = require(file);
require("read")({
prompt: "Password: "
}, function(err, password) {
console.log("");
if (err) {
return;
}
var hash = bcrypt.hashSync(password, 8);
user.password = hash;
fs.writeFileSync(
file,
JSON.stringify(user, null, " "),
{mode: "0777"}
);
console.log("Successfully reset password for '" + name + "'.");
console.log("");
});
});