Fix eslint styling issues

This commit is contained in:
Élie Michel 2017-03-21 15:49:54 +01:00
parent 642442c041
commit ed3b4faa62

View File

@ -286,18 +286,19 @@ function ldapAuth(client, user, password, callback) {
if (!user) { if (!user) {
return callback(false); return callback(false);
} }
var config = Helper.config;
var userDN = user.replace(/([,\\/#+<>;"= ])/g, "\\$1"); var userDN = user.replace(/([,\\/#+<>;"= ])/g, "\\$1");
var ldapclient = ldap.createClient({ var ldapclient = ldap.createClient({
url: Helper.config.ldap.url, url: config.ldap.url,
tlsOptions: Helper.config.ldap.tlsOptions tlsOptions: config.ldap.tlsOptions
}); });
var base = Helper.config.ldap.base; var base = config.ldap.base;
var searchOptions = { var searchOptions = {
scope: Helper.config.ldap.scope, scope: config.ldap.scope,
filter: '(&(' + Helper.config.ldap.primaryKey + '=' + userDN + ')' + Helper.config.ldap.filter + ')', filter: "(&(" + config.ldap.primaryKey + "=" + userDN + ")" + config.ldap.filter + ")",
attributes: ['dn'] attributes: ["dn"]
}; };
ldapclient.on("error", function(err) { ldapclient.on("error", function(err) {
@ -305,44 +306,43 @@ function ldapAuth(client, user, password, callback) {
callback(!err); callback(!err);
}); });
ldapclient.bind(Helper.config.ldap.rootDN, ldapclient.bind(config.ldap.rootDN, config.ldap.rootPassword, function(err) {
Helper.config.ldap.rootPassword,
function(err) {
if (err) { if (err) {
log.error("Invalid LDAP root credentials"); log.error("Invalid LDAP root credentials");
ldapclient.unbind(); ldapclient.unbind();
callback(false); callback(false);
} else { } else {
ldapclient.search(base, searchOptions, function(err, res) { ldapclient.search(base, searchOptions, function(err2, res) {
if (err) { if (err2) {
log.warning("User not found: ", userDN); log.warning("User not found: ", userDN);
ldapclient.unbind(); ldapclient.unbind();
callback(false); callback(false);
} else { } else {
var found = false; var found = false;
res.on('searchEntry', function(entry) { res.on("searchEntry", function(entry) {
found = true; found = true;
var bindDN = entry.objectName; var bindDN = entry.objectName;
log.info("Auth against LDAP ", Helper.config.ldap.url, " with bindDN ", bindDN); log.info("Auth against LDAP ", config.ldap.url, " with bindDN ", bindDN);
ldapclient.unbind() ldapclient.unbind();
var ldapclient2 = ldap.createClient({ var ldapclient2 = ldap.createClient({
url: Helper.config.ldap.url, url: config.ldap.url,
tlsOptions: Helper.config.ldap.tlsOptions tlsOptions: config.ldap.tlsOptions
}); });
ldapclient2.bind(bindDN, password, function(err) { ldapclient2.bind(bindDN, password, function(err3) {
if (!err && !client) { if (!err3 && !client) {
if (!manager.addUser(user, null)) { if (!manager.addUser(user, null)) {
log.error("Unable to create new user", user); log.error("Unable to create new user", user);
} }
} }
ldapclient2.unbind(); ldapclient2.unbind();
callback(!err); callback(!err3);
}); });
}); });
res.on('error', function(resErr) { res.on("error", function(err3) {
log.error("LDAP error: ", err3);
callback(false); callback(false);
}); });
res.on('end', function(result) { res.on("end", function() {
if (!found) { if (!found) {
callback(false); callback(false);
} }