Added 'shout reset' command
This commit is contained in:
parent
428f63946b
commit
d53c0716e6
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "shout",
|
||||
"description": "A web IRC client",
|
||||
"version": "0.25.0",
|
||||
"version": "0.25.1",
|
||||
"author": "Mattias Erming",
|
||||
"preferGlobal": true,
|
||||
"bin": {
|
||||
|
@ -47,16 +47,12 @@ program
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
bcrypt.hash(password, 8, function(err, hash) {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
manager.addUser(
|
||||
name,
|
||||
hash
|
||||
);
|
||||
console.log("Added '" + name + "'.");
|
||||
console.log("");
|
||||
});
|
||||
var hash = hashSync(password, 8);
|
||||
manager.addUser(
|
||||
name,
|
||||
hash
|
||||
);
|
||||
console.log("Added '" + name + "'.");
|
||||
console.log("");
|
||||
});
|
||||
});
|
||||
|
@ -6,6 +6,7 @@ require("./config");
|
||||
require("./list");
|
||||
require("./add");
|
||||
require("./remove");
|
||||
require("./reset");
|
||||
require("./edit");
|
||||
|
||||
program.parse(process.argv);
|
||||
|
39
src/command-line/reset.js
Normal file
39
src/command-line/reset.js
Normal 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("");
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user