0
Node.js, Express 및 Connect-Flash에서 플래시 메시지를 표시하는 데 문제가 있습니다.Node.js 유형 오류 connect-flash
예를 들어 오류 메시지가 표시 될 수 있지만 하나 이상의 메시지 (예 : 업데이트가 성공하면 성공 메시지, 업데이트에 문제가있는 경우 오류 메시지)를 보내려는 경우 문제가 발생합니다.
다음은 오류입니다 :
그리고 여기 내 코드의 조각을이다 :
// Routes.js
// ======================================
// CHANGE PASSWORD
// ======================================
app.get('/password', isLoggedIn, function (req, res) {
res.render('password', {
user: req.user, // get the user out of session and pass to template
error: req.flash('error'),
success: req.flash('success')
});
});
app.post('/password', isLoggedIn, function (req, res) {
// Save settings
if (req.body.newPassword == req.body.confirmNewPassword) {
User.findOne({_id: req.user._id}, function (err, user) {
user.local.password = generateHash(req.body.newPassword);
user.save(function(err) {
if (err)
throw new Error('There was a problem saving the password');
req.flash('success', 'Password updated successfully')
req.user = user;
res.redirect('password');
});
});
} else {
req.flash('error', 'Passwords did not match');
res.redirect('password');
}
});
// Jade template
// ===================
- if (error) // GET ERROR ON THIS LINE <------------
div.alert.alert-warning #{error}
- elseif (success)
div.alert.alert-success #{success}
감사합니다!