More fixes

This commit is contained in:
Kasper Rynning-Tønnesen
2018-03-13 17:44:16 +01:00
parent 6de7391be3
commit c0400d7999
10 changed files with 46 additions and 35 deletions

View File

@@ -134,29 +134,32 @@ function all_chat(msg, guid, offline, socket) {
}
function namechange(data, guid, socket, tried) {
if(!data.hasOwnProperty("name") || data.name.length > 10 ||
!data.hasOwnProperty("channel") || typeof(data.name) != "string" ||
if(!data.hasOwnProperty("channel") ||
typeof(data.channel) != "string") return;
var pw = "";
var new_password;
var first = false;
Functions.getSessionChatPass(Functions.getSession(socket), function(name, pass) {
var name = data.name;
if(data.hasOwnProperty("first")) {
first = data.first;
}
if(data.hasOwnProperty("password")) {
pw = data.password;
new_password = false;
} else if(data.hasOwnProperty("new_password") && data.hasOwnProperty("old_password")) {
pw = data.old_password;
new_password = Functions.decrypt_string(socket.zoff_id, data.new_password);
}
if(data.hasOwnProperty("first") && data.first) {
pw = pass;
name = name;
data.name = name;
data.password = pass;
new_password = false;
} else {
var name = data.name;
if(data.hasOwnProperty("first")) {
first = data.first;
}
if(data.hasOwnProperty("password")) {
pw = data.password;
new_password = false;
} else if(data.hasOwnProperty("new_password") && data.hasOwnProperty("old_password")) {
pw = data.old_password;
new_password = Functions.decrypt_string(socket.zoff_id, data.new_password);
}
}
var password = Functions.decrypt_string(socket.zoff_id, pw);
db.collection("registered_users").find({"_id": name.toLowerCase()}, function(err, docs) {
var accepted_password = false;
@@ -178,6 +181,9 @@ function namechange(data, guid, socket, tried) {
Functions.setSessionChatPass(Functions.getSession(socket), name.toLowerCase(), data.new_password, function() {
db.collection("registered_users").update({"_id": name.toLowerCase(), password: Functions.hash_pass(password)}, {$set: {password: Functions.hash_pass(new_password)}}, function() {});
});
} else {
Functions.setSessionChatPass(Functions.getSession(socket), name.toLowerCase(), data.password, function() {
});
}
}
if(accepted_password) {
@@ -204,7 +210,9 @@ function namechange(data, guid, socket, tried) {
}
});
} else {
socket.emit('name', {type: "name", accepted: false});
Functions.removeSessionChatPass(Functions.getSession(socket), function() {
socket.emit('name', {type: "name", accepted: false});
});
}
});
});

View File

@@ -206,7 +206,7 @@ function getSessionChatPass(id, callback) {
var pass = "";
if(d[0].name != undefined) name = d[0].name;
if(d[0].password != undefined) pass = d[0].password;
callback(name, password);
callback(name, pass);
return;
} else {
callback("", "", false);
@@ -266,8 +266,21 @@ function removeSessionChatPass(id, callback) {
});
}
function removeSessionAdminPass(id, channel, callback) {
if(id == "empty") {
callback();
return;
}
connected_db.collection(id).remove({_id: channel}, function() {
callback();
return;
});
}
module.exports.getSessionChatPass = getSessionChatPass;
module.exports.setSessionChatPass = setSessionChatPass;
module.exports.removeSessionAdminPass = removeSessionAdminPass;
module.exports.removeSessionChatPass = removeSessionChatPass;
module.exports.setSessionAdminPass = setSessionAdminPass;
module.exports.setSessionUserPass = setSessionUserPass;

View File

@@ -45,7 +45,7 @@ module.exports = function() {
});
socket.on("logout", function() {
Functions.setSessionAdminPass(Functions.getSession(socket), "", coll, function() {})
Functions.removeSessionAdminPass(Functions.getSession(socket), "", coll, function() {})
});
socket.on('chromecast', function(msg) {