Skip to content
This repository was archived by the owner on Aug 17, 2021. It is now read-only.

Use recaptcha.net where google is not available. #234

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
var provider = this;
var config = {};
provider.onLoadFunctionName = 'vcRecaptchaApiLoaded';

config.domain = "https://www.google.com";

/**
* Sets the reCaptcha configuration values which will be used by default is not specified in a specific directive instance.
Expand Down Expand Up @@ -45,6 +47,18 @@
provider.setTheme = function(theme){
config.theme = theme;
};

/**
* Sets the reCaptcha domain to enable it to work globally.
* More info here https://developers.google.com/recaptcha/docs/faq
*
* @since 2.5.0
* @param bool Fixes https://github.com/google/recaptcha/issues/87 by enabling recaptcha globally
*
*/
provider.setGlobal = function(bool){
config.domain = bool && "https://recaptcha.net";
};

/**
* Sets the reCaptcha stoken which will be used by default is not specified in a specific directive instance.
Expand Down Expand Up @@ -146,7 +160,7 @@
// Check if grecaptcha.render is not defined already.
if (isRenderFunctionAvailable()) {
callback();
} else if ($window.document.querySelector('script[src^="https://www.google.com/recaptcha/api.js"]')) {
} else if ($window.document.querySelector('script[src^="'+config.domain+'/recaptcha/api.js"]')) {
// wait for script to be loaded.
var intervalWait = $interval(function() {
if (isRenderFunctionAvailable()) {
Expand All @@ -159,7 +173,7 @@
var script = $window.document.createElement('script');
script.async = true;
script.defer = true;
script.src = 'https://www.google.com/recaptcha/api.js?onload='+provider.onLoadFunctionName+'&render=explicit';
script.src = config.domain+'/recaptcha/api.js?onload='+provider.onLoadFunctionName+'&render=explicit';
$document.find('body')[0].appendChild(script);
}

Expand Down