mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Improved how naming works on join
- XXXX changed name to YYYY doesn't happen if the user already is signed in - Signs automatically in on frontpage join
This commit is contained in:
@@ -301,13 +301,41 @@ function generate_name(guid, announce_payload, second, round) {
|
||||
}
|
||||
|
||||
function get_name(guid, announce_payload, first) {
|
||||
if(!announce_payload.announce && announce_payload.hasOwnProperty("socket")) {
|
||||
Functions.getSessionChatPass(Functions.getSession(announce_payload.socket), function(name, pass) {
|
||||
if(name == "" || pass == "") {
|
||||
get_name_generate(guid, announce_payload, first);
|
||||
return;
|
||||
}
|
||||
db.collection("registered_users").find({"_id": name.toLowerCase()}, function(err, docs) {
|
||||
if(docs[0].password == Functions.hash_pass(Functions.decrypt_string(pass))) {
|
||||
var icon = false;
|
||||
if(docs[0].icon) {
|
||||
icon = docs[0].icon;
|
||||
}
|
||||
Functions.setSessionChatPass(Functions.getSession(announce_payload.socket), name.toLowerCase(), pass, function() {
|
||||
});
|
||||
db.collection("user_names").update({"guid": guid}, {$set: {name: name, icon: icon}}, {upsert: true}, function(err, docs) {
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: name}}, function(err, docs) {
|
||||
name = name;
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
get_name_generate(guid, announce_payload, first);
|
||||
}
|
||||
}
|
||||
|
||||
function get_name_generate(guid, announce_payload, first) {
|
||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||
if(docs.length == 0) {
|
||||
generate_name(guid, announce_payload);
|
||||
} else {
|
||||
name = docs[0].name;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.get_history = get_history;
|
||||
|
||||
@@ -38,7 +38,7 @@ function remove_unique_id(short_id) {
|
||||
db.collection("unique_ids").update({"_id": "unique_ids"}, {$pull: {unique_ids: short_id}}, function(err, docs) {});
|
||||
}
|
||||
|
||||
function remove_name_from_db(guid, name) {
|
||||
function remove_name_from_db(guid) {
|
||||
// Use temporary, with caution. Can bottleneck in large quantity of users.
|
||||
//
|
||||
// Find a way of indexing users in lists in a clever way, to avoid the search here
|
||||
|
||||
@@ -48,7 +48,7 @@ module.exports = function() {
|
||||
var in_list = false;
|
||||
var name = "";
|
||||
var short_id;
|
||||
Chat.get_name(guid, {announce: false});
|
||||
Chat.get_name(guid, {announce: false, socket: socket});
|
||||
var offline = false;
|
||||
var chromecast_object = false;
|
||||
|
||||
@@ -273,7 +273,7 @@ module.exports = function() {
|
||||
});
|
||||
});
|
||||
}
|
||||
Functions.remove_name_from_db(guid, name);
|
||||
Functions.remove_name_from_db(guid);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -754,7 +754,7 @@ function getNextSong(coll, socket, callback) {
|
||||
function left_channel(coll, guid, short_id, in_list, socket, change) {
|
||||
if(!coll) {
|
||||
if(!change) {
|
||||
Functions.remove_name_from_db(guid, name);
|
||||
Functions.remove_name_from_db(guid);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -772,7 +772,7 @@ function left_channel(coll, guid, short_id, in_list, socket, change) {
|
||||
io.to(coll).emit("viewers", new_doc[0].users.length);
|
||||
socket.leave(coll);
|
||||
if(!change) {
|
||||
Functions.remove_name_from_db(guid, name);
|
||||
Functions.remove_name_from_db(guid);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -782,7 +782,7 @@ function left_channel(coll, guid, short_id, in_list, socket, change) {
|
||||
//if(updated.nModified > 0) {
|
||||
db.collection("connected_users").update({"_id": "total_users"}, {$pull: {total_users: guid + coll}}, function(err, updated){});
|
||||
if(!change) {
|
||||
Functions.remove_name_from_db(guid, name);
|
||||
Functions.remove_name_from_db(guid);
|
||||
}
|
||||
//}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user