Fakultas Ilmu Komputer UI

Commit 11c594c2 authored by Yogi Perdana's avatar Yogi Perdana
Browse files

Merge branch '1906438115-231' into 'master'

1906438115-231: Implement google recaptcha for company register (client side)

See merge request !273
parents 544092be b17d8188
Pipeline #26821 failed with stages
in 8 minutes and 55 seconds
......@@ -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);
});
});
......@@ -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,8 +99,13 @@ export default class CompanyRegisterModal extends React.Component {
}
};
handleRecaptchaValue = (value) => {
this.setState({ recaptchaValue: value });
};
handleSubmit = (e) => {
e.preventDefault();
if(this.state.recaptchaValue != null){
this.setState({ loading: true });
Server.submit('/register/', this.state).then((response) => {
Storage.set('user-data', response);
......@@ -107,6 +114,10 @@ export default class CompanyRegisterModal extends React.Component {
this.setState({ loading: false });
this.modalAlert.open('Gagal Membuat Akun', Dumper.dump(r));
}));
}
else {
this.modalAlert.open('Pastikan anda bukan robot', Dumper.dump());
}
};
render() {
......@@ -209,6 +220,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" />
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment