Skip to content

Commit

Permalink
Merge branch 'johncylee-emitter'
Browse files Browse the repository at this point in the history
  • Loading branch information
vesse committed Jan 2, 2017
2 parents b0556e5 + c585768 commit 756c823
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ var options = {
...
};
var auth = new LdapAuth(options);
auth.on('error', function (err) {
console.error('LdapAuth: ', err);
});
...
auth.authenticate(username, password, function(err, user) { ... });
...
Expand Down
13 changes: 12 additions & 1 deletion lib/ldapauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var ldap = require('ldapjs');
var debug = console.warn;
var format = require('util').format;
var bcrypt = require('bcryptjs');
var inherits = require('util').inherits;
var EventEmitter = require('events').EventEmitter;

// Get option that may be defined under different names, but accept
// the first one that is actually defined in the given object
Expand Down Expand Up @@ -109,6 +111,8 @@ function LdapAuth(opts) {
this.opts.groupSearchScope || (this.opts.groupSearchScope = 'sub');
this.opts.groupDnProperty || (this.opts.groupDnProperty = 'dn');

EventEmitter.call(this);

if (opts.cache) {
var Cache = require('./cache');
this.userCache = new Cache(100, 300, this.log, 'user');
Expand All @@ -132,6 +136,13 @@ function LdapAuth(opts) {
this._adminBound = false;
this._userClient = ldap.createClient(this.clientOpts);

var self = this;
function emitErr(err) {
self.emit('error', err);
}
this._adminClient.on('error', emitErr);
this._userClient.on('error', emitErr);

if (opts.cache) {
this._salt = bcrypt.genSaltSync();
}
Expand All @@ -153,7 +164,7 @@ function LdapAuth(opts) {
}
}
};

inherits(LdapAuth, EventEmitter);

LdapAuth.prototype.close = function (callback) {
var self = this;
Expand Down

0 comments on commit 756c823

Please sign in to comment.