Node.js Flash消息不会显示在页面

时间:2017-06-22 05:49:04

标签: javascript node.js html5 flash-message

代码运行时没有在我的服务器终端上出现任何错误,但我无法在网页上进行闪光按摩。这是我的完整代码:

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>

1 个答案:

答案 0 :(得分:1)

您的代码使用message作为变量:

res.render('signup',{message: req.flash('emailmessage')})

但您的模板使用emailmessage

{{emailmessage}}