我的登录页面上的表单错误消息未显示(用户名,密码无效,凭据丢失) 但是在我的注册页面中,出现了味精错误(需要用户名,需要电子邮件等)
passport.use(new LocalStrategy(
function(username, password, done) {
User.getUserByUsername(username, (err, user) => {
if(err) throw err;
if(!user) {
return done(null, false, {message : 'unknown user'});
}
User.comparePassword(password, user.password, (err, isMatch) => {
if(err) throw err;
if(isMatch) {
return done(null, user);
} else {
return done(null, false, {message:'invalid apssword'});
}
})
});
}));
router.post('/login',
passport.authenticate('local', {successRedirect:'/', failureRedirect:'/users/login', badRequestMessage: 'Missing credentials !!' , failureFlash: true}),
(req, res) => {
res.redirect('/');
})
我的登录文件html
<center>
<ul style="list-style-type: none;">
<li>
<a style="text-decoration:none;" href="/users/register">Signup</a>
<a style="text-decoration:none;" href="/users/login">Login</a>
</li>
</ul>
<h2>Login</h2>
{{#if errors}}
{{#each errors}}
<div>{{msg}}</div>
{{/each}}
{{/if}}
<form method="post" action="/users/login">
<div>
<input type="text" name="username" placeholder="Identifiant">
</div>
<div>
<input type="password" name="password" placeholder="Mot de passe">
</div>
<button type="submit">Login</button>
</form>
</center>
请帮助