gpt4 book ai didi

javascript - Node.js Flash 消息不显示在页面上

转载 作者:太空宇宙 更新时间:2023-11-04 00:20:37 25 4
gpt4 key购买 nike

代码运行时在我的服务器终端上没有出现任何错误,但我无法在网页上获得 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>

最佳答案

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

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

但是您的模板使用emailmessage:

{{emailmessage}}

关于javascript - Node.js Flash 消息不显示在页面上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44691113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com