0
我想用戶登錄node.js和貓鼬。 用戶註冊成功並且數據在mongodb集合中插入,但是當我嘗試使用註冊的電子郵件和密碼登錄時,頁面顯示404錯誤。用戶登錄不能與node.js和貓鼬
login.js
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
res.render('login', { title: 'Express' });
});
router.post('/login', function(req, res, next){
user.findOne({email:req.body.email}, function(err, user){
if(!user){
res.render('login',{title:'Invalid'});
}
else{
if(req.body.password===user.password){
res.render('/dashboard',{title:'Success Fully login'});
}
else{
res.render('login',{title:'invalide password'});
}
}
});
});
module.exports = router;
login.ejs
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<div style="margin:0 auto ; width:50%; padding:20px">
<form action="/login" method="post">
<label>Email</label>
<input type="text" name="email">
<br /> <br /> <br /> <br />
<label>Pass</label>
<input type="text" name="password">
<br /> <br /> <br /> <br />
<button>Login</button>
</form>
</div>
</body>
</html>
哪個頁面給404? '/'或'/ login'? –
點擊登錄按鈕後其重定向到http://本地主機:3000 /登錄和顯示未找到 錯誤:在d未找到 :\ ANGULAR JS \ WebstormProjects \ uDatabase \ app.js:45:13 (d:\ ANGULAR JS \ WebstormProjects \ uDatabase \)中的Layer.handle [as handle_request](d:\ ANGULAR JS \ WebstormProjects \ uDatabase \ node_modules \ express \ lib \ router \ layer.js:95:5) node_modules \ express \ lib \ router \ index.js:312:13) –
看不到任何東西_obvious_ wrong。你如何添加導出的路線來表達? –