Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Initialize recaptcha only when sitekey is present
Browse files Browse the repository at this point in the history
  • Loading branch information
FaZeRs committed Jul 27, 2018
1 parent e8423b3 commit 9595ca0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
30 changes: 22 additions & 8 deletions public/js/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,22 @@ component.options.__file = "resources/assets/js/pages/contact.vue"

this.$validator.validateAll().then(function (result) {
if (result) {
_this.$refs.recaptcha.execute();
if (_this.$refs.recaptcha) {
_this.$refs.recaptcha.execute();
} else {
_this.send();
}
}
});
},

onCaptchaVerified: function onCaptchaVerified(recaptchaToken) {
this.$refs.recaptcha.reset();
this.send();
},
send: function send() {
var _this2 = this;

this.$refs.recaptcha.reset();
__WEBPACK_IMPORTED_MODULE_0_axios___default.a.post('/api/contact/send', {
name: this.name,
email: this.email,
Expand All @@ -261,7 +268,9 @@ component.options.__file = "resources/assets/js/pages/contact.vue"
this.email = '';
this.message = '';
this.$validator.reset();
this.$refs.recaptcha.reset();
if (this.$refs.recaptcha) {
this.$refs.recaptcha.reset();
}
},

onCaptchaExpired: function onCaptchaExpired() {
Expand Down Expand Up @@ -698,11 +707,16 @@ var render = function() {
1
),
_vm._v(" "),
_c("vue-recaptcha", {
ref: "recaptcha",
attrs: { sitekey: _vm.sitekey, size: "invisible" },
on: { verify: _vm.onCaptchaVerified, expired: _vm.onCaptchaExpired }
}),
_vm.sitekey
? _c("vue-recaptcha", {
ref: "recaptcha",
attrs: { sitekey: _vm.sitekey, size: "invisible" },
on: {
verify: _vm.onCaptchaVerified,
expired: _vm.onCaptchaExpired
}
})
: _vm._e(),
_vm._v(" "),
_c("v-btn", { on: { click: _vm.submit } }, [
_vm._v(_vm._s(_vm.$t("send_message")))
Expand Down
15 changes: 12 additions & 3 deletions resources/assets/js/components/ContactForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<v-flex xs12>
<v-textarea v-validate="'required'" :label="$t('message')" v-model="message" :error-messages="errors.collect('message')" data-vv-name="message"/>
</v-flex>
<vue-recaptcha ref="recaptcha" :sitekey="sitekey" size="invisible" @verify="onCaptchaVerified" @expired="onCaptchaExpired"/>
<vue-recaptcha v-if="sitekey" ref="recaptcha" :sitekey="sitekey" size="invisible" @verify="onCaptchaVerified" @expired="onCaptchaExpired"/>
<v-btn @click="submit">{{ $t('send_message') }}</v-btn>
<v-btn @click="clear">{{ $t('clear') }}</v-btn>
</v-layout>
Expand Down Expand Up @@ -60,12 +60,19 @@ export default {
submit () {
this.$validator.validateAll().then((result) => {
if (result) {
this.$refs.recaptcha.execute()
if(this.$refs.recaptcha) {
this.$refs.recaptcha.execute()
} else {
this.send()
}
}
})
},
onCaptchaVerified: function (recaptchaToken) {
this.$refs.recaptcha.reset()
this.send()
},
send () {
axios.post('/api/contact/send', {
name: this.name,
email: this.email,
Expand All @@ -85,7 +92,9 @@ export default {
this.email = ''
this.message = ''
this.$validator.reset()
this.$refs.recaptcha.reset()
if(this.$refs.recaptcha) {
this.$refs.recaptcha.reset()
}
},
onCaptchaExpired: function () {
this.$refs.recaptcha.reset()
Expand Down

0 comments on commit 9595ca0

Please sign in to comment.