Я пытаюсь подтвердить вход в систему с помощью Google CAPTCHA на angularjs с nodejs сервером, когда пользователь входит в систему без проверки Google CAPTCHA, он не может войти в систему без подтверждения, но здесь пользователь может авторизоваться с проверкой капчи.
логин. html
<div ng-controller="LoginFormController" style="margin-top: 100px !important;" class="block-center wd-xl">
<form role="form" validate-form="" novalidate="">
<div name="captcha" class="g-recaptcha" data-sitekey="my_key_here" data-callback="verifyCaptcha" ng-model="account.captcha" ng-class="{ 'is-invalid': form.submitted && captcha.invalid }" required></div>
<div id="g-recaptcha-error"></div>
<button type="submit" name="submit" style="font-size:17px;height: 40px;" ng-click="signIn(account)" class="btn btn-block btn-primary btn-lg">Login</button>
</form>
</div>
<script src='https://www.google.com/recaptcha/api.js'></script>
<script>
function verifyCaptcha(){
document.getElementById('g-recaptcha-error').innerHTML = '';
}
</script>
логин. js
App.controller('LoginFormController', ['$scope', '$rootScope', '$http', '$state', 'ConUsers', '$cookieStore', '$localStorage', 'UserRoles', 'Cities', function($scope, $rootScope, $http, $state, ConUsers, $cookieStore, $localStorage, UserRoles, Cities) {
$scope.account = {};
$scope.authMsg = '';
$scope.signIn = function(user) {//login to admin portal
$scope.authMsg = '';
var email = user.email;
var password = user.password;
var captcha = user.captcha;
if ((email !== "" && password !== "" && captcha !== "")) {
ConUsers.login({//login service
email: email,
password: password,
captcha: captcha
},)
}
captcha = grecaptcha.getResponse();
if(captcha.length == 0) {
document.getElementById('g-recaptcha-error').innerHTML = '<span style="color:red;">This field is required.</span>';
return false;
}
return true;
ConUsers.login({
email: $cookieStore.get('userEmail'),
password: $cookieStore.get('userPwd'),
captcha:$scope.get('captcha')
},
function(res) {
// error
if (res.status === 401) {
$scope.authMsg = 'Please enter valid credentials';
} else if (res.status === 400) {
$scope.authMsg = 'Please enter valid email';
} else if(captcha.length == 0) {
document.getElementById('g-recaptcha-error').innerHTML = '<span style="color:red;">This field is required.</span>';
}
else {
$scope.authMsg = 'Service is not available. Please try again later';
}
// console.log('Login Error: ' + JSON.stringify([res]));
$rootScope.loader = 0;
});