From 803ebb3630eab37db54d6fd0a3b19488a0605e9b Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Thu, 15 Oct 2020 11:49:13 -0300 Subject: [PATCH] Adds google recaptcha validation. #388. --- .eslintrc.js | 3 +- src/views/admin/js/axios.js | 3 +- .../admin/js/store/modules/item/actions.js | 17 +++++++++++ .../class-tainacan-gutenberg-block.php | 7 +++++ .../pages/item-submission-form.vue | 30 ++++++++++++++++++- .../theme-search/pages/theme-items-page.vue | 24 ++++++++++++++- src/views/theme-search/scss/_layout.scss | 10 +++++++ 7 files changed, 90 insertions(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index a4e6f2f2a..ea9ee2a4f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -31,6 +31,7 @@ module.exports = { '_': true, 'jQuery': true, 'tainacan_extra_components': true, - 'tainacan_extra_plugins': true + 'tainacan_extra_plugins': true, + 'grecaptcha': true } } \ No newline at end of file diff --git a/src/views/admin/js/axios.js b/src/views/admin/js/axios.js index e0a514ac1..1b500c5c0 100644 --- a/src/views/admin/js/axios.js +++ b/src/views/admin/js/axios.js @@ -97,5 +97,6 @@ wp.interceptors.response.use( export const CancelToken = axios.CancelToken; export const isCancel = axios.isCancel; export const all = axios.all; +export const axiosCreate = axios.create; -export default { tainacan, wp, CancelToken, isCancel, all }; \ No newline at end of file +export default { tainacan, wp, CancelToken, isCancel, all, axiosCreate }; \ No newline at end of file diff --git a/src/views/admin/js/store/modules/item/actions.js b/src/views/admin/js/store/modules/item/actions.js index e78d91469..0ee6294ea 100644 --- a/src/views/admin/js/store/modules/item/actions.js +++ b/src/views/admin/js/store/modules/item/actions.js @@ -384,4 +384,21 @@ export const finishItemSubmission = ({ commit }, { itemSubmission, fakeItemId }) }); }); }); +} + +export const verifyCaptcha = ({ commit }, { secret, response }) => { + return new Promise((resolve, reject) => { + + // New axios instance + const googleReCaptcha = axios.axiosCreate({ + baseURL: 'https://www.google.com/recaptcha/api/' + }); + + googleReCaptcha.post('/verify/', { secret: secret, response: response }) + .then( res => { + resolve( res.data ); + }).catch( error => { + reject(error); + }); + }); } \ No newline at end of file diff --git a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php index 495ce8bcd..5e20bd898 100644 --- a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php +++ b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php @@ -178,6 +178,13 @@ function tainacan_blocks_register_tainacan_item_submission_form(){ array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor') ); + wp_register_script( + 'google-recaptcha-script', + 'https://www.google.com/recaptcha/api.js', + [], false, true + ); + wp_enqueue_script('google-recaptcha-script'); + wp_register_style( 'item-submission-form', $TAINACAN_BASE_URL . '/assets/css/tainacan-gutenberg-block-item-submission-form.css', diff --git a/src/views/item-submission/pages/item-submission-form.vue b/src/views/item-submission/pages/item-submission-form.vue index 9c2620f7d..5cc97851a 100644 --- a/src/views/item-submission/pages/item-submission-form.vue +++ b/src/views/item-submission/pages/item-submission-form.vue @@ -320,6 +320,14 @@ v-html="formHooks['item']['end-right'].join('')"/> + + +