Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

No event is fiered when invalid UID is used (when no match found) #292

Closed
dpvenkatesh opened this issue Aug 19, 2015 · 3 comments
Closed
Labels

Comments

@dpvenkatesh
Copy link

[SUB: No event is fiered when invalid UID is used (when no match found)]
Hi,
I am not able catch any event for non existing user.

For valid user I AM able to CATCH result.on('searchEntry' ,function()

//email = ddd.p@xxxxx.com
username = ddd.p
opts = {
    filter: '(&(uid=' + username + ')(objectclass=posixAccount))',
    attributes: ['dn', 'cn', 'mail', 'gidNumber'],
    scope: 'sub'
};



client.search('dc=xxxxx,dc=com', opts, function (error, result, nxt) {
    if (error) {
       //err
    }

    result.on('searchEntry', function (entry) {
        client.bind(entry.dn, password, function (err) {
        if (err === null) {
          //valid user
        }
        });
     });

 });

I have gone through documentation but didnt found a way to do it,

Please guide me how can I handle.

p.s. : if username is valid, inside "searchEntry" I can check for valid password. but I counld find a way to capture invalid username

@pfmooney
Copy link
Contributor

Because search yields an emitter, you must also subscribe to the error event there.

@dpvenkatesh
Copy link
Author

I do subscribed to error , as per documentation error event will be fired only if any network issues or similar issues, not on successful code execution.

however I used a work around for this problem,

var isUserExist = false; // flag

//email = ddd.p@xxxxx.com
username = ddd.p
opts = {
    filter: '(&(uid=' + username + ')(objectclass=posixAccount))',
    attributes: ['dn', 'cn', 'mail', 'gidNumber'],
    scope: 'sub'
};



client.search('dc=xxxxx,dc=com', opts, function (error, result, nxt) {
    if (error) {
       //err
    }
    result.on('searchEntry', function (entry) {

        isUserExist = true; // searchEntry fired IFF match found

        client.bind(entry.dn, password, function (err) {
        if (err === null) {
          //valid user
        }
        });
     });

    result.on(end, function(err){
         if(!isUserExist){
             console.log("user not found");
         }
    });
 });


@pfmooney pfmooney closed this as completed Sep 8, 2015
@jsumners
Copy link
Member

⚠️ This issue has been locked due to age. If you have encountered a recent
problem that seems to be covered by this issue, please open a new issue.

Please include a minimal reproducible example
when opening a new issue.

@ldapjs ldapjs locked as resolved and limited conversation to collaborators Mar 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants