2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2017-07-18 09:36:24 +00:00
|
|
|
const colors = require("colors/safe");
|
|
|
|
const program = require("commander");
|
|
|
|
const fs = require("fs");
|
|
|
|
const Helper = require("../helper");
|
2017-08-21 05:49:32 +00:00
|
|
|
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-07-18 09:36:24 +00:00
|
|
|
if (!fs.existsSync(Helper.USERS_PATH)) {
|
|
|
|
log.error(`${Helper.USERS_PATH} does not exist.`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ClientManager = require("../clientManager");
|
|
|
|
|
2014-09-11 21:00:08 +00:00
|
|
|
var users = new ClientManager().getUsers();
|
2017-08-23 05:42:59 +00:00
|
|
|
|
|
|
|
if (users === undefined) { // There was an error, already logged
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:00:08 +00:00
|
|
|
if (users.indexOf(name) === -1) {
|
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;
|
|
|
|
}
|
2016-05-08 06:21:31 +00:00
|
|
|
var file = Helper.getUserConfigPath(name);
|
2014-09-11 21:00:08 +00:00
|
|
|
var user = require(file);
|
2016-12-16 07:27:41 +00:00
|
|
|
log.prompt({
|
|
|
|
text: "Enter new password:",
|
2017-11-15 06:35:15 +00:00
|
|
|
silent: true,
|
2014-09-11 21:00:08 +00:00
|
|
|
}, function(err, password) {
|
|
|
|
if (err) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-21 19:00:43 +00:00
|
|
|
user.password = Helper.password.hash(password);
|
2017-06-21 07:58:29 +00:00
|
|
|
user.sessions = {};
|
2014-09-11 21:00:08 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
file,
|
2016-06-19 17:16:50 +00:00
|
|
|
JSON.stringify(user, null, "\t")
|
2014-09-11 21:00:08 +00:00
|
|
|
);
|
2016-12-15 06:13:43 +00:00
|
|
|
log.info(`Successfully reset password for ${colors.bold(name)}.`);
|
2014-09-11 21:00:08 +00:00
|
|
|
});
|
|
|
|
});
|