我已将我的登录表单放在bootstrap模式组件中。在输入字段内输入值并单击提交后,没有任何反应,模式只是关闭。在网络标签下的检查元素内,我没有看到任何发布请求。 使用passport-local进行授权,使用mysql作为数据库。 这是我的html代码段
<div class="modal fade" id="login" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="login modal">Login</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form method="post" action="/login"></form>
<div class="modal-body">
<div class="form-group">
<label for="Email login">Email address</label>
<input type="email" name="email" class="form-control" id="Email login" aria-describedby="emailHelp" placeholder="Enter email">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="Password login">Password</label>
<input type="password" name="password" class="form-control" id="Password login" placeholder="Password">
</div>
<div class="form-check">
<input type="checkbox" name="remember" class="form-check-input" id="remember">
<label class="form-check-label" for="exampleCheck1">Remember Me</label>
</div>
<!-- <button type="submit" class="btn btn-primary">Submit</button> -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success" data-dismiss="modal">Submit</button>
</div>
</form>
</div>
</div>
</div>
这是route.js代码
route.get('/login', (req, res) => {
res.render('login')
})
route.post(
'/login',
passport.authenticate('local', {
successRedirect: '../chat',
failureRedirect: '/',
failureFlash: false,
badRequestMessage: 'Please enter your account credentials to login.'
}),
function(req, res) {
console.log(req.param('remember'));
if(req.isAuthenticated(req, res)) {
res.redirect('../chat');
} else {
var errors = req.flash('error');
if(errors) {
assign['errors'] = errors;
}
res.render('index.html', {errors: errors});
}
}
);
这里聊天是我父目录中的文件夹,我想在成功登录后重定向用户。 请尽快调查一下。我已经尝试调试这个大约40天了。我知道这可能是一个小错误的语法错误,这让我不知所措。 谢谢
答案 0 :(得分:0)
从提交按钮中删除(data-dismiss =&#34; modal&#34;),data-dismiss在执行前关闭弹出窗口。
答案 1 :(得分:0)
在此处删除结束表单标记:
<form method="post" action="/login"></form>