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

87 lines
1.6 KiB
Vue
Raw Normal View History

<script>
2018-10-10 03:06:25 -04:00
import DeprecatedModal from './deprecated_modal.vue';
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.google.com/recaptcha/api.js',
};
},
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() {
window.recaptchaDialogCallback = this.submit.bind(this);
},
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">
<p>
{{ __('We want to be sure it is you, please confirm you are not a robot.') }}
</p>
<div
ref="recaptcha"
v-html="html"
>
</div>
</div>
</deprecated-modal>
</template>