| 18 | // Export |
| 19 | module.exports.login = function(options, username, password) { |
| 20 | function tryConnect() { |
| 21 | var resolver = Promise.defer() |
| 22 | var client = ldap.createClient({ |
| 23 | url: options.url |
| 24 | , timeout: options.timeout |
| 25 | , maxConnections: 1 |
| 26 | }) |
| 27 | |
| 28 | if (options.bind.dn) { |
| 29 | client.bind(options.bind.dn, options.bind.credentials, function(err) { |
| 30 | if (err) { |
| 31 | resolver.reject(err) |
| 32 | } |
| 33 | else { |
| 34 | resolver.resolve(client) |
| 35 | } |
| 36 | }) |
| 37 | } |
| 38 | else { |
| 39 | resolver.resolve(client) |
| 40 | } |
| 41 | |
| 42 | return resolver.promise |
| 43 | } |
| 44 | |
| 45 | function tryFind(client) { |
| 46 | var resolver = Promise.defer() |