'use strict';

// Doc: https://github.com/vesse/passport-ldapauth#readme
const LdapStrategy = require('passport-ldapauth');

const util = require('../../middleware/util');

exports.init = function (passport, router, config) {
    passport.use(new LdapStrategy(
        config,
        function (user, done) {
            done(null, {
                provider: 'ldap',
                email: user.mail,
                uid: user.uid ? user.uid[0] : null
            });
        }
    ));

    router.post('/login/ldap', util.parseBody(), passport.authenticate('ldapauth', {
        successRedirect: '/auth/login',
        failureRedirect: '/auth/login'
    }));
};

@@ -318,18 +318,20 @@
     
-done(null,
+const data =
  %7B%0A 
@@ -417,58 +417,354 @@
     
-uid: user.uid ? user.uid%5B0%5D : null%0A            %7D);
+info: %7B%7D%0A            %7D;%0A            if (typeof config.getUserInfo === 'function') %7B%0A                return Promise.resolve(config.getUserInfo(user)).then(info =%3E %7B%0A                    data.info = info;%0A                    done(null, data);%0A                %7D, err =%3E done(err));%0A            %7D else %7B%0A                done(null, data);%0A            %7D
 %0A   

allow custom getUserInfo for ldap auth