Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var router = express.Router();
- var tools = require('./authenticateUser');
- router.post('/authenticateUser', function(req, res) {
- // In the below line i am calling the method which
- // should return the userDN (a string)
- tools.searchUser(req.body.user, req.body.passwd);
- res.render('home.jade');
- });
- module.exports = {
- searchUser : function (username, password) {
- adminDN = *************;
- adminPassword = '*********';
- baseDN = '***';
- var ldap = require('ldapjs');
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
- var adminClient = ldap.createClient({
- url: '*******'
- });
- var opts = {
- filter: '(&(objectClass=userProxyFull)(sAMAccountName=' + username + '))',
- scope: 'sub',
- attribute: ['sAMAccountName']
- };
- console.log('--- going to try to connect user ---');
- try {
- adminClient.bind(adminDN, adminPassword, function (error) {
- if (error) {
- console.log(error.message);
- adminClient.unbind(function (error) {
- if (error) {
- console.log(error.message);
- } else {
- console.log('adminClient disconnected');
- }
- });
- } else {
- // Searching Client ID in LDS
- adminClient.search(baseDN, opts, function (error, search) {
- console.log('Searching.....' + userDN);
- search.on('searchEntry', function (entry) {
- if (entry.object) {
- // Here i need to return the object back
- //to the router.js from where i call in a synchronous way
- adminClient.unbind(function (error) {
- if (error) {
- console.log(error.message);
- }
- });
- }
- });
- search.on('error', function (error) {
- console.error('error: ' + error.message);
- });
- });
- }
- });
- } catch (error) {
- console.log(error);
- adminClient.unbind(function (error) {
- if (error) {
- console.log(error.message);
- } else {
- console.log('client disconnected');
- }
- });
- } finally {
- adminClient.unbind(function (error) {
- if (error) {
- console.log(error.message);
- } else {
- console.log('client disconnected');
- }
- });
- }
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement