2015-11-07 39 views
0
app.post('/login',function(req,res){ 
var email=req.param("email"); 
var password=req.param("password"); 
var val; 
var url1="mongodb://localhost:27017/login"; 
mongo.connect(url1, function(){ 
    var db= mongo.collection('login1'); 
    db.findOne({username: email}, function(err,user){ 
     var hash=user.password; 
     bcrypt.compare(password, hash, function(err, result) { 
      if(err){ 
       console.log("error"); 
      } 
      console.log("result"+result); 
      if(result) 
      { 
       console.log("its true"); 
       //Want to redirect to a ejs page called welcome something like res.render("welcome"); 
      } 
      else 
       { 
       console.log("invalid"); 
       } 

     }); 
    }); 

}); 
    }); 

想要重定向到ejs頁面,稱爲welcome類似res.render(「welcome」);。不能在比較函數中識別res,因爲不能在res中使用它。可能是一個愚蠢的問題,但有人可以幫忙嗎?想要在使用crypt的認證之後在節點中重定向頁面

回答

0

在您的代碼中,您可以使用res.redirect重定向到另一個頁面。

例如,如果你有渲染你的網站的安全部分的路線:

app.get('/welcome', ..., function(req, res, next) { 
    res.render('welcome'); 
}); 

您可以使用

res.redirect('/home'); 

將用戶重定向到您的網站的安全區域。

相關問題