1
代碼運行時沒有在我的服務器終端上發生任何錯誤,但我無法在網頁上獲得Flash按摩。這是我的全碼:Node.js Flash消息不會顯示在頁面上
passport.js:
if(user) {
return done(null, false, req.flash('emailmessage', 'That email is already taken'));
} else {
var userPassword = generateHash(password);
var data = {
email:email,
password:userPassword
};
}
auth.js:
app.get('/signup', authController.signup,function (req, res, next) {
res.render('signup',{message: req.flash('emailmessage')})
});
app.post('/signup', passport.authenticate('local-signup', {
successRedirect: '/dashboard',
failureRedirect: '/signup',
failureFlash : true
}));
mysignup.hbs:
{{emailmessage}}
<div id="frmCheckUsername">
<form id="signup" name="signup" method="post" action="/signup">
<p><label for="email">Email Address</label>
<input class="text" name="email" type="email" id="email" required class="demoInputBox" onBlur="checkAvailability()"/><span id="user-availability-status"></span></p>
<p><label for="password">Password</label>
<input name="password" type="password" required/></p>
<input class="btn" name="signbtn" type="submit" id="signbtn" value="Sign Up" />
</form>
<span id="signspano" ></span>
</div>
使用閃光燈的消息需要req.flash()函數。您可以使用[flash](https://github.com/expressjs/flash)中間件。 –
@YiKai我已經var flash = require('connect-flash'); –
而會話中間件呢? Flash中間件需要會話中間件才能工作。 –