Change 'users/' folder structure
This commit is contained in:
parent
dcdec78c4e
commit
1a620e1d54
|
@ -31,7 +31,7 @@ ClientManager.prototype.loadUsers = function() {
|
|||
ClientManager.prototype.loadUser = function(name) {
|
||||
try {
|
||||
var json = fs.readFileSync(
|
||||
Helper.HOME + "/users/" + name + "/user.json",
|
||||
Helper.HOME + "/users/" + name + ".json",
|
||||
"utf-8"
|
||||
);
|
||||
json = JSON.parse(json);
|
||||
|
@ -39,9 +39,6 @@ ClientManager.prototype.loadUser = function(name) {
|
|||
console.log(e);
|
||||
return;
|
||||
}
|
||||
if (!json) {
|
||||
return;
|
||||
}
|
||||
if (!this.findClient(name)) {
|
||||
this.clients.push(new Client(
|
||||
this.sockets,
|
||||
|
@ -60,14 +57,13 @@ ClientManager.prototype.getUsers = function() {
|
|||
mkdirp.sync(path);
|
||||
try {
|
||||
users = fs.readdirSync(path);
|
||||
users =_.map(users, function(name) {
|
||||
return name.replace(".json", "");
|
||||
});
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
return;
|
||||
}
|
||||
users = _.without(
|
||||
users,
|
||||
"example"
|
||||
);
|
||||
return users;
|
||||
};
|
||||
|
||||
|
@ -77,16 +73,16 @@ ClientManager.prototype.addUser = function(name, password) {
|
|||
return false;
|
||||
}
|
||||
try {
|
||||
var path = Helper.HOME + "/users/" + name;
|
||||
var path = Helper.HOME + "/users";
|
||||
var user = {
|
||||
user: name,
|
||||
password: password || "",
|
||||
log: false,
|
||||
networks: []
|
||||
};
|
||||
fs.mkdirSync(path);
|
||||
mkdirp.sync(path);
|
||||
fs.writeFileSync(
|
||||
path + "/user.json",
|
||||
path + "/" + name + ".json",
|
||||
JSON.stringify(user, null, " "),
|
||||
{mode: "0777"}
|
||||
);
|
||||
|
@ -102,9 +98,8 @@ ClientManager.prototype.removeUser = function(name) {
|
|||
return false;
|
||||
}
|
||||
try {
|
||||
var path = Helper.HOME + "/users/" + name;
|
||||
fs.unlinkSync(path + "/user.json");
|
||||
fs.rmdirSync(path);
|
||||
var path = Helper.HOME + "/users/" + name + ".json";
|
||||
fs.unlinkSync(path);
|
||||
} catch(e) {
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -54,11 +54,11 @@ function add(manager, name, password) {
|
|||
console.log("");
|
||||
var salt = bcrypt.genSaltSync(8);
|
||||
var hash = bcrypt.hashSync(password, salt);
|
||||
manager.addUser(
|
||||
var x = manager.addUser(
|
||||
name,
|
||||
hash
|
||||
);
|
||||
console.log("User '" + name + "' created:");
|
||||
console.log(Helper.HOME + "/users/" + name + "/user.json");
|
||||
console.log(Helper.HOME + "/users/" + name + ".json");
|
||||
console.log("");
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ module.exports = function(options) {
|
|||
var app = express()
|
||||
.use(index)
|
||||
.use(express.static("client"));
|
||||
|
||||
app.enable("trust proxy");
|
||||
|
||||
var server = null;
|
||||
var https = config.https || {};
|
||||
|
|
Loading…
Reference in New Issue