gitlab-org--gitlab-foss/app/assets/javascripts/vue_shared/components/recaptcha_modal.vue

90 lines
1.7 KiB
Vue
Raw Normal View History

<script>
2018-10-10 03:06:25 -04:00
import DeprecatedModal from './deprecated_modal.vue';
import { eventHub } from './recaptcha_eventhub';
2018-10-10 03:06:25 -04:00
export default {
name: 'RecaptchaModal',
2018-10-10 03:06:25 -04:00
components: {
DeprecatedModal,
},
2018-10-10 03:06:25 -04:00
props: {
html: {
type: String,
required: false,
default: '',
2018-01-06 13:59:49 -05:00
},
2018-10-10 03:06:25 -04:00
},
2018-10-10 03:06:25 -04:00
data() {
return {
script: {},
scriptSrc: 'https://www.recaptcha.net/recaptcha/api.js',
2018-10-10 03:06:25 -04:00
};
},
2018-10-10 03:06:25 -04:00
watch: {
html() {
this.appendRecaptchaScript();
2018-01-06 13:59:49 -05:00
},
2018-10-10 03:06:25 -04:00
},
2018-10-10 03:06:25 -04:00
mounted() {
eventHub.$on('submit', this.submit);
if (this.html) {
this.appendRecaptchaScript();
}
2018-10-10 03:06:25 -04:00
},
beforeDestroy() {
eventHub.$off('submit', this.submit);
},
2018-10-10 03:06:25 -04:00
methods: {
appendRecaptchaScript() {
this.removeRecaptchaScript();
2018-10-10 03:06:25 -04:00
const script = document.createElement('script');
script.src = this.scriptSrc;
script.classList.add('js-recaptcha-script');
script.async = true;
script.defer = true;
2018-10-10 03:06:25 -04:00
this.script = script;
2018-10-10 03:06:25 -04:00
document.body.appendChild(script);
},
2018-10-10 03:06:25 -04:00
removeRecaptchaScript() {
if (this.script instanceof Element) this.script.remove();
},
2018-10-10 03:06:25 -04:00
close() {
this.removeRecaptchaScript();
this.$emit('close');
},
2018-10-10 03:06:25 -04:00
submit() {
this.$el.querySelector('form').submit();
2018-01-06 13:59:49 -05:00
},
2018-10-10 03:06:25 -04:00
},
};
</script>
<template>
<deprecated-modal
2018-01-06 13:59:49 -05:00
:hide-footer="true"
:title="__('Please solve the reCAPTCHA')"
2018-06-11 05:49:47 -04:00
kind="warning"
class="recaptcha-modal js-recaptcha-modal"
2018-01-06 13:59:49 -05:00
@cancel="close"
>
<div slot="body">
2018-11-16 15:07:38 -05:00
<p>{{ __('We want to be sure it is you, please confirm you are not a robot.') }}</p>
<div ref="recaptcha" v-html="html"></div>
2018-01-06 13:59:49 -05:00
</div>
</deprecated-modal>
</template>