提交 59d7a0a69d00759b39b35df07585b0ad2a8277dc

作者 fanwh
1 个父辈 4665e1bf

no message

@@ -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) {
1 { 1 {
2 "name": "egg-ldapjs", 2 "name": "egg-ldapjs",
3 - "version": "1.0.0", 3 + "version": "1.0.1",
4 "description": "openldap ldap", 4 "description": "openldap ldap",
5 "eggPlugin": { 5 "eggPlugin": {
6 "name": "ldapjs" 6 "name": "ldapjs"
@@ -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
注册登录 后发表评论