正在显示
3 个修改的文件
包含
7 行增加
和
5 行删除
... | ... | @@ -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) { | ... | ... |
... | ... | @@ -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 | ... | ... |
请
注册
或
登录
后发表评论