0
我已經使用護照本地策略構建了登錄頁面身份驗證。在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.
Marwen喜後刪除
res.redirect('/');
,我刪除了res.redirect( '/');在評論//console.log(req.body)之後。現在我沒有收到我以前遇到的錯誤。但是當我嘗試使用正確的憑據登錄時,它不會重定向到索引視圖。輸入用戶名和密碼後,登錄頁面變爲靜態,點擊提交按鈕,它不會引導到索引頁面。你能幫我解決嗎? –嗨,你應該發佈另一個問題,你應該解決這個問題。 –