From ea3192d2016543aeb0ed0e5a5279138cee93d3ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=81=E6=B2=BB=E5=B9=B3?= Date: Mon, 24 Oct 2016 22:18:18 +0800 Subject: [PATCH 1/7] Install react-google-recaptcha --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index f83ba0a..ade8f7e 100644 --- a/package.json +++ b/package.json @@ -115,6 +115,7 @@ "react-bootstrap": "^0.30.5", "react-dom": "^15.0.2", "react-ga": "^2.1.2", + "react-google-recaptcha": "^0.5.4", "react-helmet": "^3.0.2", "react-intl": "^2.1.2", "react-native": "^0.31.0", From 757f63a8a8aed7433e582d6131dbf4dcbefc28d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=81=E6=B2=BB=E5=B9=B3?= Date: Mon, 24 Oct 2016 22:58:47 +0800 Subject: [PATCH 2/7] Add configs --- configs/project/client.js | 1 + configs/project/recaptcha/client.js | 11 +++++++++++ configs/project/recaptcha/credential.tmpl.js | 11 +++++++++++ configs/project/server.js | 1 + 4 files changed, 24 insertions(+) create mode 100644 configs/project/recaptcha/client.js create mode 100644 configs/project/recaptcha/credential.tmpl.js diff --git a/configs/project/client.js b/configs/project/client.js index c6e585a..4efd779 100755 --- a/configs/project/client.js +++ b/configs/project/client.js @@ -8,4 +8,5 @@ module.exports = { trackingID: 'UA-86112397-1', }, }, + recaptcha: require('./recaptcha/client'), }; diff --git a/configs/project/recaptcha/client.js b/configs/project/recaptcha/client.js new file mode 100644 index 0000000..24f1d28 --- /dev/null +++ b/configs/project/recaptcha/client.js @@ -0,0 +1,11 @@ +module.exports = { + development: { + siteKey: '6LfQGgoUAAAAAANHp6AvQOYD81JU9GnThpiIK7pH', + }, + test: { + siteKey: '6LfQGgoUAAAAAANHp6AvQOYD81JU9GnThpiIK7pH', + }, + production: { + siteKey: '6LeoHAoUAAAAAHKlo43OuPREJb22GLmik2HSaFC1', + }, +}; diff --git a/configs/project/recaptcha/credential.tmpl.js b/configs/project/recaptcha/credential.tmpl.js new file mode 100644 index 0000000..11d5f79 --- /dev/null +++ b/configs/project/recaptcha/credential.tmpl.js @@ -0,0 +1,11 @@ +module.exports = { + development: { + secretKey: 'akb48akb48akb48akb48akb48akb48akb48akb48', + }, + test: { + secretKey: 'akb48akb48akb48akb48akb48akb48akb48akb48', + }, + production: { + secretKey: 'akc49akc49akc49akc49akc49akc49akc49akc49', + }, +}; diff --git a/configs/project/server.js b/configs/project/server.js index 00b5313..deb8eb6 100755 --- a/configs/project/server.js +++ b/configs/project/server.js @@ -18,5 +18,6 @@ if (process.env.TRAVIS) { facebook: require('./passportStrategy/facebook/credential'), linkedin: require('./passportStrategy/linkedin/credential'), }, + recaptcha: require('./recaptcha/credential'), }; } From 563116ba8dabb88fe58f9ff95ce9901480528db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=81=E6=B2=BB=E5=B9=B3?= Date: Tue, 25 Oct 2016 00:39:16 +0800 Subject: [PATCH 3/7] Add recaptcha type for FormField --- src/common/components/utils/BsForm.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/common/components/utils/BsForm.js b/src/common/components/utils/BsForm.js index 049654d..974698f 100644 --- a/src/common/components/utils/BsForm.js +++ b/src/common/components/utils/BsForm.js @@ -4,6 +4,8 @@ import BsFormGroup from 'react-bootstrap/lib/FormGroup'; import Col from 'react-bootstrap/lib/Col'; import ControlLabel from 'react-bootstrap/lib/ControlLabel'; import HelpBlock from 'react-bootstrap/lib/HelpBlock'; +import Recaptcha from 'react-google-recaptcha'; +import configs from '../../../../configs/project/client'; class BsForm extends Component { getChildContext() { @@ -65,7 +67,20 @@ let BsFormField = ({ let isShowError = meta && meta.touched && meta.error; let formControl = null; - if (options) { + if (type === 'recaptcha') { + // ref: + // - + /* eslint-disable */ + formControl = configs.recaptcha ? ( + + ) : ( +
Recaptcha is disabled
+ ); + /* eslint-enable */ + } else if (options) { // ref: formControl = ( options.map((option) => ( From 20edeca8262af58335972e6aec0ab2e267b5d6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=81=E6=B2=BB=E5=B9=B3?= Date: Tue, 25 Oct 2016 00:39:44 +0800 Subject: [PATCH 4/7] Add recaptcha for RegisterForm --- src/common/components/forms/RegisterForm.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/common/components/forms/RegisterForm.js b/src/common/components/forms/RegisterForm.js index cb9d87f..1f2a4b4 100644 --- a/src/common/components/forms/RegisterForm.js +++ b/src/common/components/forms/RegisterForm.js @@ -8,6 +8,7 @@ import userAPI from '../../api/user'; import { validateForm } from '../../actions/formActions'; import { pushErrors } from '../../actions/errorActions'; import { Form, FormField, FormFooter } from '../utils/BsForm'; +import configs from '../../../../configs/project/client'; const validate = (values) => { const errors = {}; @@ -24,6 +25,10 @@ const validate = (values) => { errors.password = 'Required'; } + if (configs.recaptcha && !values.recaptcha) { + errors.recaptcha = 'Required'; + } + return errors; }; @@ -90,6 +95,12 @@ class RegisterForm extends Component { type="password" placeholder="Password" /> +