Skip to content

Commit

Permalink
Removing duplicate user profile -issue#2943
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinikammar committed Jun 23, 2020
1 parent c895aff commit 1df64eb
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/clientManager.js
Expand Up @@ -35,34 +35,38 @@ ClientManager.prototype.init = function (identHandler, sockets) {

ClientManager.prototype.findClient = function (name) {
name = name.toLowerCase();
return this.clients.find((u) => {
const clientName = u.name;
return clientName.toLowerCase() === name;
});
return this.clients.find((u) => u.name.toLowerCase() === name);
};

ClientManager.prototype.loadUsers = function () {
const usersList = this.getUsers();

const users = usersList.reduce((refinedUsersList, user) => {
const normalize = (x) => x.toLowerCase();
const normalizedUser = normalize(user);

if (refinedUsersList.every((otherUser) => normalize(otherUser) !== normalizedUser)) {
refinedUsersList.push(user);
} else {
log.error(`Removing user profile '${user}' as this is a duplicate entry`);
}

return refinedUsersList;
}, []);
let users = this.getUsers();

if (users.length === 0) {
log.info(
`There are currently no users. Create one with ${colors.bold("thelounge add <name>")}.`
);

return;
}

const alreadySeenUsers = new Set();
users = users.filter((user) => {
user = user.toLowerCase();

if (alreadySeenUsers.has(user)) {
log.error(
`There is more than one user named "${colors.bold(
user
)}". Usernames are now case insensitive, duplicate users will not load.`
);

return false;
}
alreadySeenUsers.add(user);

return true;
});

// This callback is used by Auth plugins to load users they deem acceptable
const callbackLoadUser = (user) => {
this.loadUser(user);
Expand Down

0 comments on commit 1df64eb

Please sign in to comment.