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', () => { ...@@ -47,6 +47,14 @@ describe('CompanyRegisterModal', () => {
expect(companyRegister.categoryOptions).to.exist; 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', () => { it('handle password validation', () => {
const password = '3s24Aasd'; const password = '3s24Aasd';
expect(validatePassword(password)).to.equal(true); expect(validatePassword(password)).to.equal(true);
...@@ -58,4 +66,11 @@ describe('CompanyRegisterModal', () => { ...@@ -58,4 +66,11 @@ describe('CompanyRegisterModal', () => {
); );
expect(companyRegister.state.benefits).to.exist; 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'; ...@@ -7,6 +7,7 @@ import ModalAlert from './ModalAlert';
import Server from '../lib/Server'; import Server from '../lib/Server';
import Storage from '../lib/Storage'; import Storage from '../lib/Storage';
import Dumper from '../lib/Dumper'; import Dumper from '../lib/Dumper';
import ReCAPTCHA from "react-google-recaptcha";
export default class CompanyRegisterModal extends React.Component { export default class CompanyRegisterModal extends React.Component {
constructor(props) { constructor(props) {
...@@ -19,6 +20,7 @@ export default class CompanyRegisterModal extends React.Component { ...@@ -19,6 +20,7 @@ export default class CompanyRegisterModal extends React.Component {
{ text: 'Mempermudah mencari calon peserta magang' }, { text: 'Mempermudah mencari calon peserta magang' },
{ text: 'Dan banyak keuntungan lainnya' }, { text: 'Dan banyak keuntungan lainnya' },
], ],
recaptchaValue: null,
}; };
this.handleChange = this.handleChange.bind(this); this.handleChange = this.handleChange.bind(this);
this.handleFile = this.handleFile.bind(this); this.handleFile = this.handleFile.bind(this);
...@@ -97,16 +99,25 @@ export default class CompanyRegisterModal extends React.Component { ...@@ -97,16 +99,25 @@ export default class CompanyRegisterModal extends React.Component {
} }
}; };
handleRecaptchaValue = (value) => {
this.setState({ recaptchaValue: value });
};
handleSubmit = (e) => { handleSubmit = (e) => {
e.preventDefault(); e.preventDefault();
this.setState({ loading: true }); if(this.state.recaptchaValue != null){
Server.submit('/register/', this.state).then((response) => { this.setState({ loading: true });
Storage.set('user-data', response); Server.submit('/register/', this.state).then((response) => {
browserHistory.push('/home'); Storage.set('user-data', response);
}, (error) => error.then((r) => { browserHistory.push('/home');
this.setState({ loading: false }); }, (error) => error.then((r) => {
this.modalAlert.open('Gagal Membuat Akun', Dumper.dump(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() { render() {
...@@ -209,6 +220,10 @@ export default class CompanyRegisterModal extends React.Component { ...@@ -209,6 +220,10 @@ export default class CompanyRegisterModal extends React.Component {
<label htmlFor="address">Website</label> <label htmlFor="address">Website</label>
<Input onChange={this.handleChange} placeholder="Website perusahaan anda" name="website" required /> <Input onChange={this.handleChange} placeholder="Website perusahaan anda" name="website" required />
</Form.Field> </Form.Field>
<ReCAPTCHA
sitekey="6LfUYMYUAAAAAF_Yj073qov9JOMrYQaNIu3-UIF7"
onChange={(value) => { this.handleRecaptchaValue(value); }}
/>
<Modal.Actions style={{ textAlign: 'right' }}> <Modal.Actions style={{ textAlign: 'right' }}>
<Button type="reset" color="red"> <Button type="reset" color="red">
<Icon name="remove" /> <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