2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-09-11 21:00:08 +00:00
|
|
|
var ClientManager = new require("../clientManager");
|
|
|
|
var fs = require("fs");
|
|
|
|
var program = require("commander");
|
2014-09-13 12:23:17 +00:00
|
|
|
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) {
|
2016-04-16 11:32:38 +00:00
|
|
|
log.error("User '" + name + "' doesn't 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);
|
|
|
|
require("read")({
|
2016-03-31 23:28:25 +00:00
|
|
|
prompt: "[thelounge] New password: ",
|
2014-09-14 00:09:21 +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);
|
2016-05-31 21:28:31 +00:00
|
|
|
user.token = null; // Will be regenerated when the user is loaded
|
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-04-16 11:32:38 +00:00
|
|
|
log.info("Successfully reset password for '" + name + "'.");
|
2014-09-11 21:00:08 +00:00
|
|
|
});
|
|
|
|
});
|