2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2018-06-15 20:31:06 +00:00
|
|
|
const log = require("../../log");
|
2018-03-02 18:28:54 +00:00
|
|
|
const colors = require("chalk");
|
2017-07-18 09:36:24 +00:00
|
|
|
const program = require("commander");
|
|
|
|
const fs = require("fs");
|
2017-12-07 02:23:46 +00:00
|
|
|
const Helper = require("../../helper");
|
|
|
|
const Utils = require("../utils");
|
2014-09-11 21:00:08 +00:00
|
|
|
|
|
|
|
program
|
|
|
|
.command("reset <name>")
|
|
|
|
.description("Reset user password")
|
2017-08-21 05:49:32 +00:00
|
|
|
.on("--help", Utils.extraHelp)
|
2014-09-11 21:00:08 +00:00
|
|
|
.action(function(name) {
|
2017-12-07 03:54:54 +00:00
|
|
|
if (!fs.existsSync(Helper.getUsersPath())) {
|
|
|
|
log.error(`${Helper.getUsersPath()} does not exist.`);
|
2017-07-18 09:36:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-07 02:23:46 +00:00
|
|
|
const ClientManager = require("../../clientManager");
|
2017-12-07 02:28:21 +00:00
|
|
|
const users = new ClientManager().getUsers();
|
2017-08-23 05:42:59 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
if (users === undefined) {
|
|
|
|
// There was an error, already logged
|
2017-08-23 05:42:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-22 06:39:32 +00:00
|
|
|
if (!users.includes(name)) {
|
2016-12-15 06:13:43 +00:00
|
|
|
log.error(`User ${colors.bold(name)} does not exist.`);
|
2014-09-11 21:00:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const file = Helper.getUserConfigPath(name);
|
|
|
|
const user = require(file);
|
2019-07-17 09:33:59 +00:00
|
|
|
log.prompt(
|
|
|
|
{
|
|
|
|
text: "Enter new password:",
|
|
|
|
silent: true,
|
|
|
|
},
|
|
|
|
function(err, password) {
|
|
|
|
if (err) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
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)}.`);
|
|
|
|
}
|
|
|
|
);
|
2014-09-11 21:00:08 +00:00
|
|
|
});
|