Monday, 24 April 2017

Authentication on node js and express js 2

I have built login page authentication using passport local strategy. Part of the code in users.js goes here which is successful..

router.post('/login',
      passport.authenticate('local', {successRedirect:'/', failureRedirect:'/users/login',failureFlash: true}),
      function(req, res) {
        res.redirect('/');
      });

But I want to authenticate login using my company credentials through ldap for which I have own module called 'bluepages' which I have replaced the above block as below.

router.post('/login',function(req,res){
    //console.log(req.body);
    bluepages.authenticate(req.body.username,req.body.password,function(err,verified){
    if(err) console.log(err);
    else {
        if(verified)
            return res.redirect('/');
            //console.log('Success');
        else
            return res.redirect('/users/login');
            //console.log('Invalid Credentials');

    }
});
});

I get 'success' log when the credentials are correct and 'Invalid Credentials' log when credentials are incorrect. This is working perfect. But my requirement is when res.redirect is not directing to the required view. It remains in login page itself even though credentials are correct. Can you please help me on how to direct the views where it is not redirecting to the index view when I am trying to login using correct credentials. The login page has become static after the input of correct username and password clicking submit button it is not directing to index page it still remains in the login page and not able to see any error. Please help me on it.



via sandeep sampathu

No comments:

Post a Comment