diff --git a/src/clientManager.js b/src/clientManager.js index 127415d..ad2406d 100644 --- a/src/clientManager.js +++ b/src/clientManager.js @@ -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; } diff --git a/src/command-line/add.js b/src/command-line/add.js index 01db39d..bf7761d 100644 --- a/src/command-line/add.js +++ b/src/command-line/add.js @@ -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(""); } diff --git a/src/server.js b/src/server.js index a5be983..36059f7 100644 --- a/src/server.js +++ b/src/server.js @@ -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 || {};