diff --git a/assets/js/__test__/components/CompanyRegisterModal-test.jsx b/assets/js/__test__/components/CompanyRegisterModal-test.jsx index 9300a93492eab2750eea4a3af5494104567cf81b..6fd0d3d6fb976048167ffafa2834b1dc25e797ae 100755 --- a/assets/js/__test__/components/CompanyRegisterModal-test.jsx +++ b/assets/js/__test__/components/CompanyRegisterModal-test.jsx @@ -47,6 +47,14 @@ describe('CompanyRegisterModal', () => { expect(companyRegister.categoryOptions).to.exist; }); + it('renders recaptcha without problem', () => { + const companyRegister = ReactTestUtils.renderIntoDocument( + <CompanyRegisterModal />, + ); + const recaptcha = ReactTestUtils.scryRenderedComponentsWithType(companyRegister, 'ReCAPTCHA'); + expect(recaptcha).to.exist; + }); + it('handle password validation', () => { const password = '3s24Aasd'; expect(validatePassword(password)).to.equal(true); @@ -58,4 +66,11 @@ describe('CompanyRegisterModal', () => { ); expect(companyRegister.state.benefits).to.exist; }); + + it('Register modal state contain recaptchaValue', () => { + const companyRegister = ReactTestUtils.renderIntoDocument( + <CompanyRegisterModal />, + ); + expect(companyRegister.state.recaptchaValue).to.equal(null); + }); }); diff --git a/assets/js/components/CompanyRegisterModal.jsx b/assets/js/components/CompanyRegisterModal.jsx index d399e50fc9f93a694682330b7862a2db5df3d5b7..d9b570f6fcc52cab41441d638f0ea7d3330c00f7 100755 --- a/assets/js/components/CompanyRegisterModal.jsx +++ b/assets/js/components/CompanyRegisterModal.jsx @@ -7,6 +7,7 @@ import ModalAlert from './ModalAlert'; import Server from '../lib/Server'; import Storage from '../lib/Storage'; import Dumper from '../lib/Dumper'; +import ReCAPTCHA from "react-google-recaptcha"; export default class CompanyRegisterModal extends React.Component { constructor(props) { @@ -19,6 +20,7 @@ export default class CompanyRegisterModal extends React.Component { { text: 'Mempermudah mencari calon peserta magang' }, { text: 'Dan banyak keuntungan lainnya' }, ], + recaptchaValue: null, }; this.handleChange = this.handleChange.bind(this); this.handleFile = this.handleFile.bind(this); @@ -97,16 +99,25 @@ export default class CompanyRegisterModal extends React.Component { } }; + handleRecaptchaValue = (value) => { + this.setState({ recaptchaValue: value }); + }; + handleSubmit = (e) => { e.preventDefault(); - this.setState({ loading: true }); - Server.submit('/register/', this.state).then((response) => { - Storage.set('user-data', response); - browserHistory.push('/home'); - }, (error) => error.then((r) => { - this.setState({ loading: false }); - this.modalAlert.open('Gagal Membuat Akun', Dumper.dump(r)); - })); + if(this.state.recaptchaValue != null){ + this.setState({ loading: true }); + Server.submit('/register/', this.state).then((response) => { + Storage.set('user-data', response); + browserHistory.push('/home'); + }, (error) => error.then((r) => { + this.setState({ loading: false }); + this.modalAlert.open('Gagal Membuat Akun', Dumper.dump(r)); + })); + } + else { + this.modalAlert.open('Pastikan anda bukan robot', Dumper.dump()); + } }; render() { @@ -205,6 +216,10 @@ export default class CompanyRegisterModal extends React.Component { <label htmlFor="address">Website</label> <Input onChange={this.handleChange} placeholder="Website perusahaan anda" name="website" required /> </Form.Field> + <ReCAPTCHA + sitekey="6LfUYMYUAAAAAF_Yj073qov9JOMrYQaNIu3-UIF7" + onChange={(value) => { this.handleRecaptchaValue(value); }} + /> <Modal.Actions style={{ textAlign: 'right' }}> <Button type="reset" color="red"> <Icon name="remove" /> diff --git a/package-lock.json b/package-lock.json index 5a698af1eb0fd5f784fe44c53f9058a5663da803..78c6cf45729fe65072c0a555915ead73c1bea148 100755 --- a/package-lock.json +++ b/package-lock.json @@ -89,7 +89,6 @@ "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", "dev": true, - "optional": true, "requires": { "is-extendable": "^0.1.0" } @@ -6492,7 +6491,7 @@ "integrity": "sha1-nvxRzhnsVykIayKuiJ5dfQ4lZgE=", "dev": true, "requires": { - "esprima": "github:substack/esprima#is-keyword" + "esprima": "github:substack/esprima#0a7f8489a11b44b019ce168506f535f22d0be290" } }, "fast-deep-equal": { @@ -6835,8 +6834,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -6854,13 +6852,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -6873,18 +6869,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -6987,8 +6980,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -6998,7 +6990,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7011,20 +7002,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.3.5", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -7041,7 +7029,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -7114,8 +7101,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -7125,7 +7111,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -7201,8 +7186,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -7232,7 +7216,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -7250,7 +7233,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -7289,13 +7271,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.3", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -11301,6 +11281,25 @@ "prop-types": "^15.6.2" } }, + "react-async-script": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/react-async-script/-/react-async-script-1.1.1.tgz", + "integrity": "sha512-pmgS3O7JcX4YtH/Xy//NXylpD5CNb5T4/zqlVUV3HvcuyOanatvuveYoxl3X30ZSq/+q/+mSXcNS8xDVQJpSeA==", + "requires": { + "hoist-non-react-statics": "^3.3.0", + "prop-types": "^15.5.0" + }, + "dependencies": { + "hoist-non-react-statics": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz", + "integrity": "sha512-wbg3bpgA/ZqWrZuMOeJi8+SKMhr7X9TesL/rXMjTzh0p0JUBo3II8DHboYbuIXWRlttrUFxwcu/5kygrCw8fJw==", + "requires": { + "react-is": "^16.7.0" + } + } + } + }, "react-chartjs-2": { "version": "2.8.0", "resolved": "https://registry.npmjs.org/react-chartjs-2/-/react-chartjs-2-2.8.0.tgz", @@ -11352,6 +11351,15 @@ "scheduler": "^0.18.0" } }, + "react-google-recaptcha": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/react-google-recaptcha/-/react-google-recaptcha-2.0.1.tgz", + "integrity": "sha512-4Y8awVnarn7+gdVpu8uvSmRJzzlMMoXqdhLoyToTOfVK6oM+NaChNI8NShnu75Q2YGHLvR1IA1FWZesuYHwn5w==", + "requires": { + "prop-types": "^15.5.0", + "react-async-script": "^1.1.1" + } + }, "react-hot-loader": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/react-hot-loader/-/react-hot-loader-3.1.3.tgz", diff --git a/package.json b/package.json index 963d3428de192d50633e20e238c50e557d5beebb..00846147ea8d77293dd89ccf040a3a73a161e232 100755 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "react-ckeditor-wrapper": "^1.0.22", "react-datepicker": "^0.60.2", "react-dom": "^16.12.0", + "react-google-recaptcha": "^2.0.1", "react-router": "^3.2.5", "semantic-ui-react": "^0.79.1", "sinon": "^7.5.0",