Я пытаюсь подтвердить вход в систему с помощью Google CAPTCHA на angularjs с nodejs сервером, когда я пытаюсь войти в систему с помощью Re-CAPTCHA, я получаю http 405 ошибка не найдена, и когда я вхожу без кода CAPTCHA Проверка Я получаю следующие ошибки в консоли браузера -
base.js:5 ReferenceError: require is not defined
at Object.<anonymous> (http://192.168.1.23:8080/app/js/app.js:1006:15)
at Object.i [as invoke] (http://192.168.1.23:8080/app/js/base.js:4:17991)
at f.instance (http://192.168.1.23:8080/app/js/base.js:5:6796)
at http://192.168.1.23:8080/app/js/base.js:4:29565
at o (http://192.168.1.23:8080/app/js/base.js:4:903)
at b (http://192.168.1.23:8080/app/js/base.js:4:29549)
at s (http://192.168.1.23:8080/app/js/base.js:4:25618)
at http://192.168.1.23:8080/app/js/base.js:4:25114
at http://192.168.1.23:8080/app/js/base.js:13:22101
at oe (http://192.168.1.23:8080/app/js/base.js:5:3727)
<div ui-view="" autoscroll="false" class="ng-zoomBackDown ng-fluid ng-scope">
И когда я пытаюсь войти с проверкой, я получаю ошибку 405.
логин. html
<script>
$(document).ready(function() {
$('#comment_form').submit(function() {
$(this).ajaxSubmit({
error: function(xhr) {
status('Error: ' + xhr.status);
},
success: function(response) {
console.log(response);
}
});
//Very important line, it disable the page refresh.
return false;
});
});
</script>
access-login- js
var express = require('express');
var bodyParser = require('body-parser');
var request = require('request');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended : false}));
app.get('/',function(req,res) {
// Sending our HTML file to browser.
res.sendFile(__dirname + '/login.html');
});
app.post('/submit',function(req,res){
// g-recaptcha-response is the key that browser will generate upon form submit.
// if its blank or null means user has not selected the captcha, so return the error.
if(req.body['g-recaptcha-response'] === undefined || req.body['g-recaptcha-response'] === '' || req.body['g-recaptcha-response'] === null) {
return res.json({"responseCode" : 1,"responseDesc" : "Please select captcha"});
}
// Put your secret key here.
var secretKey = "my_key_here";
// req.connection.remoteAddress will provide IP address of connected user.
var verificationUrl = "https://www.google.com/recaptcha/api/siteverify?secret=" + secretKey + "&response=" + req.body['g-recaptcha-response'] + "&remoteip=" + req.connection.remoteAddress;
// Hitting GET request to the URL, Google will respond with success or error scenario.
request(verificationUrl,function(error,response,body) {
body = JSON.parse(body);
// Success will be true or false depending upon captcha validation.
if(body.success !== undefined && !body.success) {
return res.json({"responseCode" : 1,"responseDesc" : "Failed captcha verification"});
}
res.json({"responseCode" : 0,"responseDesc" : "Sucess"});
});
});
// This will handle 404 requests.
app.use("*",function(req,res) {
res.status(404).send("404");
})
// lifting the app on port 3000.
app.listen(3000);
}]);