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