1
我試圖將谷歌的reCAPTCHA我的註冊表格的已經有Passport身份驗證就可以了代碼後端看起來是這樣的:護照身份驗證與谷歌的reCAPTCHA
app.get('/signup', function(req, res) {
// render the page and pass in any flash data if it exists
res.render('signup.ejs', {
message : req.flash('signupMessage')
});
});
app.post('/signup', passport.authenticate('local-signup', {
successRedirect : '/app', // redirect to the secure chat section
failureRedirect : '/signup', // redirect back to the signup page if there is an error
failureFlash : true // allow flash messages
}));
這是我的谷歌recaptha代碼:
app.get('/signup', recaptcha.middleware.render, function(req, res) {
// render the page and pass in any flash data if it exists
res.render('signup.ejs', {
message : req.flash('signupMessage'),
captcha : req.recaptcha
});
});
app.post('/signup', recaptcha.middleware.verify, function(req, res){
if (!req.recaptcha.error) {
//if recaptcha is correct do somthing
}else {
req.flash('signupMessage','reCAPTCHA Incorrect');
res.redirect('/signup');
}
});
兩個獨立工作,但是當我將它們結合起來是這樣的:
app.get('/signup', isNotLoggedIn, recaptcha.middleware.render, function(req, res) {
// render the page and pass in any flash data if it exists
res.render('signup.ejs', {
message : req.flash('signupMessage'),
captcha : req.recaptcha
});
});
app.post('/signup', recaptcha.middleware.verify, function(req, res){
if (!req.recaptcha.error) {
passport.authenticate('local-signup', {
successRedirect : '/app',
failureRedirect : '/signup',
failureFlash : true
});
}else {
req.flash('signupMessage','reCAPTCHA Incorrect');
res.redirect('/signup');
}
});
或者這樣:
app.get('/signup', isNotLoggedIn, recaptcha.middleware.render, function(req, res) {
// render the page and pass in any flash data if it exists
res.render('signup.ejs', {
message : req.flash('signupMessage'),
captcha : req.recaptcha
});
});
app.post('/signup', recaptcha.middleware.verify, function(req, res){
if (req.recaptcha.error) {
req.flash('signupMessage','reCAPTCHA Incorrect');
res.redirect('/signup');
}
},
passport.authenticate('local-signup', {
successRedirect : '/app', // redirect to the secure chat section
failureRedirect : '/signup', // redirect back to the signup page if there is an error
failureFlash : true // allow flash messages
}));
頁面停留在加載並沒有什麼happends。