更改页面后 Recaptcha 无法在 angular 中获得响应

Recaptcha cant get response in angular after changing page

我的 angular 应用程序有问题。我的网站上有一个注册页面。通常,当我直接进入注册页面时,它工作正常,在提交表单后发送并注册用户。例如,当我加载注册页面然后转到登录页面然后再次注册时出现问题。在这种情况下,表单不会发送到服务器。
我试图解决这个问题,甚至在点击注册 link 后通过刷新页面来修复,但它没有帮助。

我稍微调试了我的应用程序,发现它是 recaptcha 导致我的问题。我使用 angular-recaptcha 版本 2.2.5;试图记录 vcRecaptchaService.getResponse() 的输出,但控制台中没有任何显示。

这是一些代码,问题可能出在这里:

表格请求

$scope.registerRequest = (form) => {
    $scope.$broadcast('show-errors-check-validity');
    if (!form.$valid) {
        return;
    }

    $scope.isLoading = true;
    $scope.formData.reCaptcha = vcRecaptchaService.getResponse();

    apiRequest.post('user/register', $scope.formData).success((response) => {
        $scope.isLoading = false;
        $scope.registered = true;
        $scope.formData = {};
    });
};


路线:

app.config(['$routeProvider', ($routeProvider) => {
$routeProvider
        .when('/auth/login', {
            controller: 'authLogin',
            label: 'Logowanie',
            templateUrl: 'app/components/authLoginView.html',
            access: ['UNAUTH']
        })
        .when('/auth/register/', {
            controller: 'authRegister',
            label: 'Rejestracja',
            templateUrl: 'app/components/authRegisterView.html',
            access: ['UNAUTH']
        })
        .when('/auth/register/confirm', {
            controller: 'authRegister',
            label: 'Potwierdzenie rejestracji',
            templateUrl: 'app/components/authRegisterView.html',
            access: ['UNAUTH']
        })
        .when('/auth/register/resend', {
            controller: 'authRegister',
            label: 'Rejestracja',
            templateUrl: 'app/components/authRegisterView.html',
            access: ['UNAUTH']
        })
}]);


还有一些 HTML:

<div ng-if="section == 'register'" class="container employer-container">
    <form name="registerForm" class="form-horizontal col-sm-6 col-sm-offset-3" loader is-loading="isLoading">
        <h4 class="employer-h4">Rejestracja</h4>

        <p class="bg-success text-success col-xs-12" ng-show="registered">
            Użytkownik został zarejestrowany. Na podany adres e-mail wysłaliśmy dalsze instrukcje.
        </p>

        <div ng-hide="registered">
            <div class="form-group" show-errors>
                <label for="email" class="col-md-3 control-label">E-mail:</label>
                <div class="col-md-9">
                    <input type="text" class="form-control" id="email" placeholder="E-mail"
                           ng-model="formData.email" name="username"
                           ng-required="true">
                </div>
            </div>
            <div class="form-group" show-errors>
                <label for="password" class="col-md-3 control-label">Hasło:</label>
                <div class="col-md-9">
                    <input type="password" class="form-control" id="password" placeholder="Hasło"
                           ng-model="formData.password" name="password" ng-minlength="5"
                           ng-required="true" equals="{{ formData.confirmPassword }}">
                </div>
            </div>
            <div class="form-group" show-errors>
                <label for="confirmPassword" class="col-md-3 control-label">Powtórz hasło:</label>
                <div class="col-md-9">
                    <input type="password" class="form-control" id="confirmPassword" placeholder="Powtórz hasło"
                           ng-model="formData.confirmPassword" name="confirmPassword" ng-minlength="5"
                           ng-required="true" equals="{{ formData.password }}">
                </div>
            </div>
            <div class="form-group" show-errors>
                <label class="col-md-3 control-label" for="userType">Rodzaj konta:</label>
                <div class="col-md-9">
                    <div class="btn-group" dropdown>
                        <button type="button" class="btn btn-default dropdown-toggle form-control"
                                id="userType" name="userType" dropdown-toggle ng-model="formData.userType"
                                ng-required="true">
                            {{ userTypes[formData.userType] || 'rodzaj konta' }} <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu">
                            <li ng-repeat="(key, userType) in userTypes">
                                <a href="" ng-click="$parent.formData.userType = key">{{ ::userType }}</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="form-group" show-errors>
                <div class="col-md-3"></div>
                <div class="col-md-9">
                    <input class="form-control" type="checkbox" id="acceptTerms" ng-model="formData.acceptedTerms" name="acceptTerms" ng-required="true">
                    <label class="control-label" style="text-align: left;" for="acceptTerms">Zgadzam się z  <a href="/#!/page/4" style="color: #3C5B9B;">Regulaminem</a></label>
                </div>
            </div>
            <div class="form-group" show-errors>
                <div class="col-md-3"></div>
                <div class="col-md-9">
                    <input class="form-control" type="checkbox" id="acceptTerms2" ng-model="formData.acceptedTerms2" name="acceptTerms2" ng-required="true">
                    <label class="control-label" style="text-align: left;" for="acceptTerms2">Wyrażam zgodę na przetwarzanie moich danych w celu realizacji usług w ramach Serwisu i akceptuję <a href="/#!/page/5" style="color: #3C5B9B;">Politykę Prywatności.</a>.</label>
                </div>
            </div>
            <div class="form-group" show-errors>
                <div class="col-md-3"></div>
                <div class="col-md-9">
                    <input class="form-control" type="checkbox" id="acceptTerms3" ng-model="formData.acceptedTerms3" name="acceptTerms3" ng-required="true">
                    <label class="control-label" style="text-align: left;" for="acceptTerms3">Wyrażam zgodę na przetwarzanie moich danych w <a href="/#!/page/9" style="color: #3C5B9B;">celach marketingowych.</a></label>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-9 col-md-offset-3">
                    <div vc-recaptcha key="'key'"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-6 col-md-offset-3">
                    <a href="#!/auth/lostpassword">Zapomniane hasło</a> |
                    <a href="#!/auth/login">Logowanie</a>
                </div>
                <div class="col-md-3 text-right">
                    <button type="submit" class="btn btn-info" ng-click="registerRequest(registerForm)">Zarejestruj</button>
                </div>
            </div>
        </div>
    </form>
</div>

这里可以看到问题:http://pze2.biuro.netivo.pl/

在我的路线中回答关于 ['UNAUTH'] 的问题之一。只允许未登录的用户进入此页面。

感谢 Vinny,我设法解决了这个问题。

问题正如他在 reCaptcha.getResponse() 中所说的那样,没有得到正确的小部件。

对于那些遇到同样问题的人,我将解决方案放在我的代码中:

要求:

$scope.registerRequest = (form) => {
    $scope.$broadcast('show-errors-check-validity');
    if (!form.$valid) {
        return;
    }

    $scope.isLoading = true;

    apiRequest.post('user/register', $scope.formData).success((response) => {
        $scope.isLoading = false;
        $scope.registered = true;
        $scope.formData = {};
    });
};

HTML:

<div ng-if="section == 'register'" class="container employer-container">
    <form name="registerForm" class="form-horizontal col-sm-6 col-sm-offset-3" loader is-loading="isLoading">
        <h4 class="employer-h4">Rejestracja</h4>

        <p class="bg-success text-success col-xs-12" ng-show="registered">
            Użytkownik został zarejestrowany. Na podany adres e-mail wysłaliśmy dalsze instrukcje.
        </p>
        <div ng-hide="registered">
            ...
            <div class="form-group">
                <div class="col-md-9 col-md-offset-3">
                    <div vc-recaptcha ng-model="formData.reCaptcha" key="'key'"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-6 col-md-offset-3">
                    <a href="#!/auth/lostpassword">Zapomniane hasło</a> |
                    <a href="#!/auth/login">Logowanie</a>
                </div>
                <div class="col-md-3 text-right">
                    <button type="submit" class="btn btn-info" ng-click="registerRequest(registerForm)">Zarejestruj</button>
                </div>
            </div>
        </div>
    </form>
</div>