This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1498 from SumOfUs/feature.recaptcha-changes
Get reCAPTCHA token just before verification
- Loading branch information
Showing
13 changed files
with
109 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as React from 'react'; | ||
import { FormattedHTMLMessage } from 'react-intl'; | ||
|
||
const ReCaptchaBranding = () => ( | ||
<p className="ReCaptchaBranding"> | ||
<FormattedHTMLMessage | ||
id="recaptcha_branding_html" | ||
defaultMessage={ | ||
<p> | ||
{'This site is protected by reCAPTCHA and the Google '} | ||
<a href="https://policies.google.com/privacy">Privacy Policy </a> | ||
{' and '} | ||
<a href="https://policies.google.com/terms">Terms of Service</a> | ||
{' apply.'} | ||
</p> | ||
} | ||
/> | ||
</p> | ||
); | ||
|
||
export default ReCaptchaBranding; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import './recaptcha.css'; | ||
|
||
const MAX_RETRIES = 4; | ||
export interface IReCaptchaInstance { | ||
ready: (cb: () => any) => void; | ||
execute: (siteKey: string, options: IExecuteOptions) => Promise<string>; | ||
} | ||
interface IExecuteOptions { | ||
action: string; | ||
} | ||
|
||
export const isReady = () => { | ||
return window.grecaptcha != null && window.grecaptcha.execute != null; | ||
}; | ||
|
||
export const load = (): Promise<IReCaptchaInstance> => { | ||
if (isReady()) { | ||
return Promise.resolve(window.grecaptcha as IReCaptchaInstance); | ||
} | ||
|
||
const siteKey = window.champaign.configuration.recaptcha3.siteKey; | ||
|
||
const src = `https://www.google.com/recaptcha/api.js?render=${siteKey}`; | ||
const script = document.createElement('script'); | ||
script.type = 'text/javascript'; | ||
script.src = src; | ||
script.async = true; | ||
script.defer = true; | ||
document.body.appendChild(script); | ||
|
||
return new Promise((resolve, reject) => { | ||
let retries = 0; | ||
const id = setTimeout(() => { | ||
if (window.grecaptcha) { | ||
clearTimeout(id); | ||
return resolve(window.grecaptcha); | ||
} else if (retries >= MAX_RETRIES) { | ||
clearTimeout(id); | ||
return reject(new Error('Could not load reCAPTCHA')); | ||
} else { | ||
retries = retries + 1; | ||
} | ||
}, 400); | ||
}); | ||
}; | ||
|
||
export const execute = async (options: IExecuteOptions): Promise<string> => { | ||
const siteKey = window.champaign.configuration.recaptcha3.siteKey; | ||
const captcha = await load(); | ||
return captcha.execute(siteKey, options); | ||
}; | ||
|
||
export default { | ||
load, | ||
isReady, | ||
execute, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.grecaptcha-badge { | ||
visibility: hidden; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters