From 77adf26236855b4b43a1072ad2dc6a904bef7d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Wed, 29 Apr 2020 09:15:18 +0900 Subject: [PATCH] Factorize *captcha component --- src/client/components/captcha.vue | 119 ++++++++++++++++++++++ src/client/components/hcaptcha.vue | 77 --------------- src/client/components/signup-dialog.vue | 2 +- src/client/components/signup.vue | 33 ++++--- src/client/pages/instance/settings.vue | 125 ++++++++---------------- 5 files changed, 180 insertions(+), 176 deletions(-) create mode 100644 src/client/components/captcha.vue delete mode 100644 src/client/components/hcaptcha.vue diff --git a/src/client/components/captcha.vue b/src/client/components/captcha.vue new file mode 100644 index 000000000..6b1ee6f0b --- /dev/null +++ b/src/client/components/captcha.vue @@ -0,0 +1,119 @@ + + + diff --git a/src/client/components/hcaptcha.vue b/src/client/components/hcaptcha.vue deleted file mode 100644 index 4bc03342f..000000000 --- a/src/client/components/hcaptcha.vue +++ /dev/null @@ -1,77 +0,0 @@ - - - diff --git a/src/client/components/signup-dialog.vue b/src/client/components/signup-dialog.vue index 10cdf3a56..4db79af51 100644 --- a/src/client/components/signup-dialog.vue +++ b/src/client/components/signup-dialog.vue @@ -1,5 +1,5 @@ @@ -66,7 +66,7 @@ export default Vue.extend({ MkButton, MkInput, MkSwitch, - hCaptcha: () => import('./hcaptcha.vue').then(x => x.default), + captcha: () => import('./captcha.vue').then(x => x.default), }, data() { @@ -83,6 +83,7 @@ export default Vue.extend({ submitting: false, ToSAgreement: false, hCaptchaResponse: null, + reCaptchaResponse: null, faLock, faExclamationTriangle, faSpinner, faCheck, faKey } }, @@ -124,14 +125,6 @@ export default Vue.extend({ } }, - mounted() { - if (this.meta.enableRecaptcha) { - const script = document.createElement('script'); - script.setAttribute('src', 'https://www.google.com/recaptcha/api.js'); - document.head.appendChild(script); - } - }, - methods: { onChangeUsername() { if (this.username == '') { @@ -189,7 +182,7 @@ export default Vue.extend({ password: this.password, invitationCode: this.invitationCode, 'hcaptcha-response': this.hCaptchaResponse, - 'g-recaptcha-response': this.meta.enableRecaptcha ? (window as any).grecaptcha.getResponse() : null + 'g-recaptcha-response': this.meta.reCaptchaResponse, }).then(() => { this.$root.api('signin', { username: this.username, @@ -199,17 +192,25 @@ export default Vue.extend({ }); }).catch(() => { this.submitting = false; + this.$refs.hcaptcha?.reset?.(); + this.$refs.recaptcha?.reset?.(); this.$root.dialog({ type: 'error', text: this.$t('error') }); - - if (this.meta.enableRecaptcha) { - (window as any).grecaptcha.reset(); - } }); } } }); + + diff --git a/src/client/pages/instance/settings.vue b/src/client/pages/instance/settings.vue index 008d6ef1a..f0fa84699 100644 --- a/src/client/pages/instance/settings.vue +++ b/src/client/pages/instance/settings.vue @@ -41,15 +41,15 @@
{{ $t('hcaptcha') }}
- {{ $t('enableHcaptcha') }} + {{ $t('enableHcaptcha') }}
-
+
{{ $t('preview') }}
- +