节点js和快递js的身份验证

问题描述:

我已经使用护照本地策略构建了登录页面身份验证。在users.js部分代码放在这里是成功的..节点js和快递js的身份验证

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

但我想用我公司的凭据通过LDAP,对此我有一个名为“蓝页”自己的模块来验证登录,我已经取代了上面的块如下。

router.post('/login',function(req,res){ 
    //console.log(req.body); 
    res.redirect('/'); 
    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'); 

    } 
}); 
}); 

我获得“成功”时的凭据是正确的,“凭据无效”日志时凭据不正确登录。这是完美的。但是我的要求是,res.redirect不是指向所需的视图。即使证书是正确的,它仍然保留在登录页面中。我收到以下错误,我无法解决它。你能帮我解释一下如何引导观点。

_http_outgoing.js:344 
    throw new Error('Can\'t set headers after they are sent.'); 
    ^

Error: Can't set headers after they are sent. 

喜,你应该注释//console.log(req.body)

+0

Marwen喜后删除res.redirect('/');,我删除了res.redirect( '/');在评论//console.log(req.body)之后。现在我没有收到我以前遇到的错误。但是当我尝试使用正确的凭据登录时,它不会重定向到索引视图。输入用户名和密码后,登录页面变为静态,点击提交按钮,它不会引导到索引页面。你能帮我解决吗? –

+0

嗨,你应该发布另一个问题,你应该解决这个问题。 –