提交 59d7a0a69d00759b39b35df07585b0ad2a8277dc

作者 fanwh
1 个父辈 4665e1bf

no message

... ... @@ -6,7 +6,7 @@ const ldap = require('ldapjs');
6 6 let count = 0;
7 7
8 8 module.exports = app => {
9   - app.addSingleton('ldapjs', createClient);
  9 + app.ldapjs = createClient(app.config.ldapjs, app);
10 10 };
11 11
12 12 function createClient(config, app) {
... ... @@ -16,9 +16,10 @@ function createClient(config, app) {
16 16 app.coreLogger.info('[egg-ldapjs] connecting %s@%s:%s/%s',
17 17 config.dn, config.url);
18 18
19   - const LdapClient = options => {
  19 + const LdapClient = function(options) {
20 20 this.client = ldap.createClient(options);
21 21 };
  22 +
22 23 function promisify(fn) {
23 24 return function() {
24 25 const client = this.client;
... ... @@ -50,11 +51,13 @@ function createClient(config, app) {
50 51 const searchCallback = function(err, result) {
51 52 const r = {
52 53 entries: [],
  54 + objEntries: [],
53 55 references: [],
54 56 };
55 57
56 58 result.on('searchEntry', function(entry) {
57 59 r.entries.push(entry);
  60 + r.objEntries.push(entry.object);
58 61 });
59 62
60 63 result.on('searchReference', function(reference) {
... ...
1 1 {
2 2 "name": "egg-ldapjs",
3   - "version": "1.0.0",
  3 + "version": "1.0.1",
4 4 "description": "openldap ldap",
5 5 "eggPlugin": {
6 6 "name": "ldapjs"
... ...
... ... @@ -10,9 +10,8 @@ class HomeController extends Controller {
10 10 scope: 'sub',
11 11 attributes: [ 'dn', 'sn', 'cn', 'ou' ],
12 12 };
13   - console.log(this.app.ldapjs);
14 13 const result = await this.app.ldapjs.search('dc=dodokeroro,dc=cn', opts);
15   - console.log('result::::', result);
  14 + console.log('result::::', JSON.stringify(result.objEntries));
16 15 }
17 16 }
18 17
... ...
注册登录 后发表评论