Skip to content

Commit

Permalink
add filter for duplicate emails
Browse files Browse the repository at this point in the history
  • Loading branch information
hubermat committed Dec 7, 2019
1 parent 1acaf77 commit bd48fd1
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions ctldap.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,38 @@ Object.keys(config.sites).map(function(sitename, index) {
if (site.dn_lower_case || ((site.dn_lower_case === undefined) && config.dn_lower_case)) {
site.compatTransform = function (s) {
return s.toLowerCase();
}
};
} else {
site.compatTransform = function (s) {
return s;
}
};
}
if (site.email_lower_case || ((site.email_lower_case === undefined) && config.email_lower_case)) {
site.compatTransformEmail = function (s) {
return s ? s.toLowerCase() : s;
}
};
} else {
site.compatTransformEmail = function (s) {
return s;
}
};
}
if (site.emails_unique || ((site.emails_unique === undefined) && config.emails_unique)) {
site.uniqueEmails = function (users) {
var mails = {};
var filteredUsers = users.filter(function (user) {
if (!user.attributes.email || (user.attributes.email == '')) {
return false;
}
var result = !(user.attributes.email in mails);
mails[user.attributes.email] = true;
return result;
});
return filteredUsers;
};
} else {
site.uniqueEmails = function (users) {
return s;
};
}
if (site.ldap_password_bcrypt || ((site.ldap_password_bcrypt === undefined) && config.ldap_password_bcrypt)) {
site.checkPassword = function (password, callback) {
Expand Down Expand Up @@ -272,6 +290,7 @@ function requestUsers (req, res, next) {
}
};
});
newCache = site.uniqueEmails(newCache);
// Virtual admin user
if (site.ldap_password !== undefined) {
var cn = config.ldap_user;
Expand Down

0 comments on commit bd48fd1

Please sign in to comment.