正在显示
3 个修改的文件
包含
7 行增加
和
5 行删除
@@ -6,7 +6,7 @@ const ldap = require('ldapjs'); | @@ -6,7 +6,7 @@ const ldap = require('ldapjs'); | ||
6 | let count = 0; | 6 | let count = 0; |
7 | 7 | ||
8 | module.exports = app => { | 8 | module.exports = app => { |
9 | - app.addSingleton('ldapjs', createClient); | 9 | + app.ldapjs = createClient(app.config.ldapjs, app); |
10 | }; | 10 | }; |
11 | 11 | ||
12 | function createClient(config, app) { | 12 | function createClient(config, app) { |
@@ -16,9 +16,10 @@ function createClient(config, app) { | @@ -16,9 +16,10 @@ function createClient(config, app) { | ||
16 | app.coreLogger.info('[egg-ldapjs] connecting %s@%s:%s/%s', | 16 | app.coreLogger.info('[egg-ldapjs] connecting %s@%s:%s/%s', |
17 | config.dn, config.url); | 17 | config.dn, config.url); |
18 | 18 | ||
19 | - const LdapClient = options => { | 19 | + const LdapClient = function(options) { |
20 | this.client = ldap.createClient(options); | 20 | this.client = ldap.createClient(options); |
21 | }; | 21 | }; |
22 | + | ||
22 | function promisify(fn) { | 23 | function promisify(fn) { |
23 | return function() { | 24 | return function() { |
24 | const client = this.client; | 25 | const client = this.client; |
@@ -50,11 +51,13 @@ function createClient(config, app) { | @@ -50,11 +51,13 @@ function createClient(config, app) { | ||
50 | const searchCallback = function(err, result) { | 51 | const searchCallback = function(err, result) { |
51 | const r = { | 52 | const r = { |
52 | entries: [], | 53 | entries: [], |
54 | + objEntries: [], | ||
53 | references: [], | 55 | references: [], |
54 | }; | 56 | }; |
55 | 57 | ||
56 | result.on('searchEntry', function(entry) { | 58 | result.on('searchEntry', function(entry) { |
57 | r.entries.push(entry); | 59 | r.entries.push(entry); |
60 | + r.objEntries.push(entry.object); | ||
58 | }); | 61 | }); |
59 | 62 | ||
60 | result.on('searchReference', function(reference) { | 63 | result.on('searchReference', function(reference) { |
@@ -10,9 +10,8 @@ class HomeController extends Controller { | @@ -10,9 +10,8 @@ class HomeController extends Controller { | ||
10 | scope: 'sub', | 10 | scope: 'sub', |
11 | attributes: [ 'dn', 'sn', 'cn', 'ou' ], | 11 | attributes: [ 'dn', 'sn', 'cn', 'ou' ], |
12 | }; | 12 | }; |
13 | - console.log(this.app.ldapjs); | ||
14 | const result = await this.app.ldapjs.search('dc=dodokeroro,dc=cn', opts); | 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 |
请
注册
或
登录
后发表评论