Added 'shout reset' command

This commit is contained in:
Mattias Erming 2014-09-11 14:00:08 -07:00
parent 428f63946b
commit d53c0716e6
4 changed files with 48 additions and 12 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "shout", "name": "shout",
"description": "A web IRC client", "description": "A web IRC client",
"version": "0.25.0", "version": "0.25.1",
"author": "Mattias Erming", "author": "Mattias Erming",
"preferGlobal": true, "preferGlobal": true,
"bin": { "bin": {

View File

@ -47,10 +47,7 @@ program
if (err) { if (err) {
return; return;
} }
bcrypt.hash(password, 8, function(err, hash) { var hash = hashSync(password, 8);
if (err) {
return;
}
manager.addUser( manager.addUser(
name, name,
hash hash
@ -59,4 +56,3 @@ program
console.log(""); console.log("");
}); });
}); });
});

View File

@ -6,6 +6,7 @@ require("./config");
require("./list"); require("./list");
require("./add"); require("./add");
require("./remove"); require("./remove");
require("./reset");
require("./edit"); require("./edit");
program.parse(process.argv); program.parse(process.argv);

39
src/command-line/reset.js Normal file
View File

@ -0,0 +1,39 @@
var bcrypt = require("bcrypt");
var ClientManager = new require("../clientManager");
var fs = require("fs");
var program = require("commander");
const HOME = process.env.HOME + "/.shout";
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 = HOME + "/users/";
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("");
});
});