hardlounge/src/command-line/reset.js
Jérémie Astori 1dc92d8934
Enforce dangling commas with ESLint
¯\_(ツ)_/¯
2017-11-15 01:35:15 -05:00

49 lines
1.1 KiB
JavaScript

"use strict";
const colors = require("colors/safe");
const program = require("commander");
const fs = require("fs");
const Helper = require("../helper");
const Utils = require("./utils");
program
.command("reset <name>")
.description("Reset user password")
.on("--help", Utils.extraHelp)
.action(function(name) {
if (!fs.existsSync(Helper.USERS_PATH)) {
log.error(`${Helper.USERS_PATH} does not exist.`);
return;
}
const ClientManager = require("../clientManager");
var users = new ClientManager().getUsers();
if (users === undefined) { // There was an error, already logged
return;
}
if (users.indexOf(name) === -1) {
log.error(`User ${colors.bold(name)} does not exist.`);
return;
}
var file = Helper.getUserConfigPath(name);
var user = require(file);
log.prompt({
text: "Enter new password:",
silent: true,
}, function(err, password) {
if (err) {
return;
}
user.password = Helper.password.hash(password);
user.sessions = {};
fs.writeFileSync(
file,
JSON.stringify(user, null, "\t")
);
log.info(`Successfully reset password for ${colors.bold(name)}.`);
});
});