Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/support actions #292

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Properties used to customise the rendering:
| onErrored | func | *optional* callback when the challenge errored, most likely due to network issues. |
| onExpired | func | *optional* callback when the challenge is expired and has to be redone by user. By default it will call the onChange with null to signify expired callback. |
| sitekey | string | The API client key |
| data-action | string | Data-action may only contain only alphanumeric characters, slashes, and underscores. Data-action must not be user-specific. It is important to check the action returned in the verify response. |
| size | enum | *optional* `compact`, `normal` or `invisible`. This allows you to change the size or do an invisible captcha |
| stoken | string | *optional* set the stoken parameter, which allows the captcha to be used from different domains, see [reCAPTCHA secure-token] |
| tabindex | number | *optional* The tabindex on the element *(__default:__ `0`)*
Expand All @@ -66,6 +67,7 @@ The component instance also has some utility functions that can be called. These
- need to call when using `"invisible"` reCAPTCHA - [example below](#invisible-recaptcha)
- `executeAsync()` programmatically invoke the challenge and return a promise that resolves to the token or errors(if encountered).
- alternative approach to `execute()` in combination with the `onChange()` prop - [example below](#invisible-recaptcha)
- `getValue()` *after* the user completes the reCAPTCHA challenge programmatically get the token response for the reCAPTCHA widget.

Example:
```javascript
Expand Down
31 changes: 31 additions & 0 deletions clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable no-unused-vars */
/* eslint-env node */
"use strict";
var fs = require("fs");

function deleteFolderRecursive(path) {
if (fs.existsSync(path) && fs.lstatSync(path).isDirectory()) {
fs.readdirSync(path).forEach(function (file, index) {
var curPath = path + "/" + file;

if (fs.lstatSync(curPath).isDirectory()) {
// recurse
deleteFolderRecursive(curPath);
} else {
// delete file
fs.unlinkSync(curPath);
}
});

console.log(`Deleting directory "${path}"...`);
fs.rmdirSync(path);
}
}

console.log("Cleaning working tree...");

process.argv.forEach(function (val, index, array) {
deleteFolderRecursive("./" + val);
});

console.log("Successfully cleaned working tree!");
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lib": "lib/"
},
"scripts": {
"build": "rm -rf lib && npm run build:cjs && npm run build:esm",
"build": "node clean.js lib && npm run build:cjs && npm run build:esm",
"build:cjs": "babel src --out-dir lib",
"build:esm": "cross-env BABEL_ENV=esm babel src --out-dir lib/esm",
"prepare": "npm run build",
Expand Down
8 changes: 8 additions & 0 deletions react-google-recaptcha.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
6 changes: 3 additions & 3 deletions src/recaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ export default class ReCAPTCHA extends React.Component {
explicitRender() {
const render = this.getCaptchaFunction("render");
if (render && this._widgetId === undefined) {
const wrapper = document.createElement("div");
this._widgetId = render(wrapper, {
this._widgetId = render(this.captcha, {
sitekey: this.props.sitekey,
callback: this.handleChange,
theme: this.props.theme,
Expand All @@ -113,8 +112,8 @@ export default class ReCAPTCHA extends React.Component {
hl: this.props.hl,
badge: this.props.badge,
isolated: this.props.isolated,
"data-action": this.props.dataAction,
});
this.captcha.appendChild(wrapper);
}
if (this._executeRequested && this.props.grecaptcha && this._widgetId !== undefined) {
this._executeRequested = false;
Expand Down Expand Up @@ -173,6 +172,7 @@ ReCAPTCHA.propTypes = {
hl: PropTypes.string,
badge: PropTypes.oneOf(["bottomright", "bottomleft", "inline"]),
isolated: PropTypes.bool,
dataAction: PropTypes.string,
};
ReCAPTCHA.defaultProps = {
onChange: () => {},
Expand Down
20 changes: 20 additions & 0 deletions test/recaptcha.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ describe("ReCAPTCHA", () => {
ReCaptchaRef.current.reset();
expect(grecaptchaMock.reset).toBeCalledWith(WIDGET_ID);
});
it("getValue, should call grecaptcha.getResponse with the widget id (for legacy reasons)", () => {
const WIDGET_ID = "someWidgetId";
const grecaptchaMock = {
render() {
return WIDGET_ID;
},
getResponse: jest.fn(),
};
const ReCaptchaRef = React.createRef();
render(
<ReCAPTCHA
sitekey="xxx"
grecaptcha={grecaptchaMock}
ref={ReCaptchaRef}
onChange={jest.fn()}
/>,
);
ReCaptchaRef.current.getValue();
expect(grecaptchaMock.getResponse).toBeCalledWith(WIDGET_ID);
});
it("execute, should call grecaptcha.execute with the widget id", () => {
const WIDGET_ID = "someWidgetId";
const grecaptchaMock = {
Expand Down