Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

product and vendor - captcha changes

DanielŻuławski4ef02e5be040
diff --git a/src/Web/Grand.Web/Views/Catalog/Components/VendorContact/Default.cshtml b/src/Web/Grand.Web/Views/Catalog/Components/VendorContact/Default.cshtml
index b2510251a..3ce92a49d 100644
--- a/src/Web/Grand.Web/Views/Catalog/Components/VendorContact/Default.cshtml
+++ b/src/Web/Grand.Web/Views/Catalog/Components/VendorContact/Default.cshtml
@@ -8,12 +8,11 @@
}
else
{
- <template v-if="contactvendor.Message.Result !== null">
- <div v-bind:class="{'alert alert-info': contactvendor.Message.SuccessfullySent, 'alert alert-danger': !contactvendor.Message.SuccessfullySent}">
- {{contactvendor.Message.Result}}
- </div>
- </template>
- <template v-else>
+ <template v-if="contactvendor.Message.Result !== null && contactvendor.Message.SuccessfullySent">
+ <div class="alert alert-success">
+ {{contactvendor.Message.Result}}
+ </div>
+ </template>
<validation-observer v-slot="{ handleSubmit }">
<form asp-route="ContactVendor" id="vendorContact" method="post" ref="form" v-on:submit.prevent="handleSubmit(formSubmit($event))">
<input type="hidden" asp-for="@Model.VendorId" />
@@ -58,19 +57,16 @@ else
<span asp-validation-for="Enquiry"></span>
</validation-provider>
</div>
- @if (Model.DisplayCaptcha)
- {
- <div class="captcha-box px-3">
- <captcha />
- </div>
- }
</div>
+ @if (Model.DisplayCaptcha)
+ {
+ <div id="captcha-place"></div>
+ }
<div class="btn-group text-sm-center pt-3 pb-3">
<input type="submit" name="send-email" class="btn btn-info contact-us-button" data-form="contactvendor.submitVendorContact('@Url.RouteUrl("ContactVendor", new { vendorId = Model.VendorId })')" value="@Loc["ContactVendor.Button"]" />
</div>
</form>
</validation-observer>
- </template>
<script asp-location="Footer" asp-order="300">
var contactvendor = new Vue({
data: () => ({
@@ -87,7 +83,18 @@ else
</text>
}
}),
+ created() {
+
+ },
methods: {
+ getCaptcha() {
+ @if (Model.DisplayCaptcha) {
+ <text>
+ var html = document.getElementById("captcha-box");
+ document.getElementById("captcha-place").prepend(html);
+ </text>
+ }
+ },
submitVendorContact(url) {
var bodyFormData = new FormData(document.getElementById("vendorContact"));
axios({
@@ -102,6 +109,32 @@ else
}).then(function (response) {
contactvendor.Message.Result = response.data.Result;
contactvendor.Message.SuccessfullySent = response.data.SuccessfullySent;
+
+ var result = response.data.Result;
+ var variant = "";
+
+ if (response.data.SuccessfullySent) {
+ variant = "info";
+ document.getElementById("vendorContact").style.display = "none";
+ } else {
+ variant = "danger";
+ }
+
+ new Vue({
+ el: ".modal-place",
+ methods: {
+ toast() {
+ this.$bvToast.toast(result, {
+ variant: variant,
+ autoHideDelay: 3000,
+ solid: true
+ })
+ }
+ },
+ mounted: function () {
+ this.toast();
+ }
+ });
})
}
}
diff --git a/src/Web/Grand.Web/Views/Catalog/Components/VendorReviews/Default.cshtml b/src/Web/Grand.Web/Views/Catalog/Components/VendorReviews/Default.cshtml
index 85f133892..60678f247 100644
--- a/src/Web/Grand.Web/Views/Catalog/Components/VendorReviews/Default.cshtml
+++ b/src/Web/Grand.Web/Views/Catalog/Components/VendorReviews/Default.cshtml
@@ -4,14 +4,6 @@
<a class="btn btn-info" @@click="vendorreviews.addVendorReview()">@Loc["Reviews.Overview.AddNew"]</a>
</div>
-@if (Model.AddVendorReview.DisplayCaptcha)
-{
- <div id="captcha-container">
- <div class="captcha-box" id="captcha-box">
- <captcha />
- </div>
- </div>
-}
<partial name="_VendorReview.Modal" model="Model" />
<template id="vendor-review-list" v-if="vendorreviews.Model.Items.length > 0">
@@ -111,7 +103,7 @@
vm.$refs['ModalVendorReview'].show();
},
modalReviewShown: function () {
- if (vendorreviews.Model.AddVendorReview.DisplayCaptcha && document.querySelector("#ModalVendorReview .captcha-box") == null) {
+ if (vendorreviews.Model.AddVendorReview.DisplayCaptcha && document.querySelector("#ModalVendorReview .captcha-box") == null && !vendorreviews.Model.AddVendorReview.SuccessfullyAdded) {
var html = document.getElementById("captcha-box");
document.getElementById("captcha-popup").prepend(html);
}
diff --git a/src/Web/Grand.Web/Views/Catalog/Vendor.cshtml b/src/Web/Grand.Web/Views/Catalog/Vendor.cshtml
index d7e9796d1..8aac44450 100644
--- a/src/Web/Grand.Web/Views/Catalog/Vendor.cshtml
+++ b/src/Web/Grand.Web/Views/Catalog/Vendor.cshtml
@@ -41,11 +41,12 @@
<div class="row">
<div class="col-12">
<b-tabs class="mt-3" content-class="mt-3" align="center">
- <template v-if="catalog.Model.Description !== null">
+ @if (!String.IsNullOrEmpty(Model.Description))
+ {
<b-tab id="description-tab" title="@Loc["vendor.Description"]" active>
<article class="text-xs-center generalMarginSupporter vendor-description" v-html="catalog.Model.Description"></article>
</b-tab>
- </template>
+ }
@if (Model.Address != null)
{
<b-tab id="address-tab" title="@Loc["Vendor.Address"]">
@@ -128,16 +129,18 @@
</ul>
</b-tab>
}
- <template v-if="catalog.Model.VendorReviewOverview.AllowCustomerReviews">
+ @if (Model.VendorReviewOverview.AllowCustomerReviews)
+ {
<b-tab id="review-tab" title="@Loc["vendor.Reviews"]" :active="active ? true : false">
@await Component.InvokeAsync("VendorReviews", new { vendorId = Model.Id })
</b-tab>
- </template>
- <template v-if="catalog.Model.AllowCustomersToContactVendors">
- <b-tab id="contact-tab" title="@Loc["ContactVendor"]">
+ }
+ @if (Model.AllowCustomersToContactVendors)
+ {
+ <b-tab id="contact-tab" title="@Loc["ContactVendor"]" @@click="contactvendor.getCaptcha()">
@await Component.InvokeAsync("VendorContact", new { vendorId = Model.Id })
</b-tab>
- </template>
+ }
</b-tabs>
</div>
</div>
@@ -178,7 +181,7 @@
</template>
</div>
</div>
-@if(Model.RenderCaptcha)
+@if (Model.RenderCaptcha)
{
<div id="captcha-container">
<div class="captcha-box" id="captcha-box">
diff --git a/src/Web/Grand.Web/Views/Catalog/_VendorReview.Modal.cshtml b/src/Web/Grand.Web/Views/Catalog/_VendorReview.Modal.cshtml
index 2e31168ec..97418f7c3 100644
--- a/src/Web/Grand.Web/Views/Catalog/_VendorReview.Modal.cshtml
+++ b/src/Web/Grand.Web/Views/Catalog/_VendorReview.Modal.cshtml
@@ -46,5 +46,10 @@
</validation-observer>
</div>
</template>
+ <template v-else>
+ <div class="alert alert-info">
+ {{vendorreviews.Model.AddVendorReview.Result}}
+ </div>
+ </template>
</template>
</b-modal>
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml b/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml
index bc0fe001f..817b9609e 100644
--- a/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml
+++ b/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml
@@ -3,14 +3,6 @@
<div class="mb-3">
<a class="btn btn-info" @@click="productreviews.addProductReview()">@Loc["Reviews.Overview.AddNew"]</a>
</div>
-@if (Model.AddProductReview.DisplayCaptcha)
-{
- <div id="captcha-container">
- <div class="captcha-box" id="captcha-box">
- <captcha />
- </div>
- </div>
-}
<partial name="_ProductReview.Modal.cshtml" model="Model" />
<template id="product-review-list" v-if="productreviews.Model !== null">
@@ -121,7 +113,7 @@
vm.$refs['ModalProductReview'].show();
},
modalReviewShown: function () {
- if (productreviews.Model.AddProductReview.DisplayCaptcha && document.querySelector("#ModalProductReview .captcha-box") == null) {
+ if (productreviews.Model.AddProductReview.DisplayCaptcha && document.querySelector("#ModalProductReview .captcha-box") == null && !productreviews.Model.AddProductReview.SuccessfullyAdded) {
var html = document.getElementById("captcha-box");
document.getElementById("captcha-popup").prepend(html);
}
diff --git a/src/Web/Grand.Web/Views/Product/Components/ProductReviews/_ProductReview.Modal.cshtml b/src/Web/Grand.Web/Views/Product/Components/ProductReviews/_ProductReview.Modal.cshtml
index aac5cee85..c4f32e087 100644
--- a/src/Web/Grand.Web/Views/Product/Components/ProductReviews/_ProductReview.Modal.cshtml
+++ b/src/Web/Grand.Web/Views/Product/Components/ProductReviews/_ProductReview.Modal.cshtml
@@ -49,5 +49,10 @@
</validation-observer>
</div>
</template>
+ <template v-else>
+ <div class="alert alert-info">
+ {{productreviews.Model.AddProductReview.Result}}
+ </div>
+ </template>
</template>
</b-modal>
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Views/Product/ProductLayout.Grouped.cshtml b/src/Web/Grand.Web/Views/Product/ProductLayout.Grouped.cshtml
index 156d7ada3..2cdebfa49 100644
--- a/src/Web/Grand.Web/Views/Product/ProductLayout.Grouped.cshtml
+++ b/src/Web/Grand.Web/Views/Product/ProductLayout.Grouped.cshtml
@@ -134,7 +134,7 @@
}
@if (Model.AskQuestionOnProduct)
{
- <b-tab title="@Loc["Products.ContactUs"]">
+ <b-tab title="@Loc["Products.ContactUs"]" @if (Model.ProductAskQuestion.DisplayCaptcha) { <text> @@click="askquestion.getCaptcha()" </text> }>
<partial name="_AskQuestionOnProduct" model="Model.ProductAskQuestion" />
</b-tab>
}
diff --git a/src/Web/Grand.Web/Views/Product/ProductLayout.Simple.cshtml b/src/Web/Grand.Web/Views/Product/ProductLayout.Simple.cshtml
index e60d39b75..a38d75f88 100644
--- a/src/Web/Grand.Web/Views/Product/ProductLayout.Simple.cshtml
+++ b/src/Web/Grand.Web/Views/Product/ProductLayout.Simple.cshtml
@@ -225,7 +225,7 @@
}
@if (Model.AskQuestionOnProduct)
{
- <b-tab title="@Loc["Products.ContactUs"]">
+ <b-tab title="@Loc["Products.ContactUs"]" @if (Model.ProductAskQuestion.DisplayCaptcha) { <text> @@click="askquestion.getCaptcha()" </text> }>
<partial name="_AskQuestionOnProduct" model="Model.ProductAskQuestion" />
</b-tab>
}
diff --git a/src/Web/Grand.Web/Views/Product/_AskQuestionOnProduct.cshtml b/src/Web/Grand.Web/Views/Product/_AskQuestionOnProduct.cshtml
index b8244a224..6b8ba176e 100644
--- a/src/Web/Grand.Web/Views/Product/_AskQuestionOnProduct.cshtml
+++ b/src/Web/Grand.Web/Views/Product/_AskQuestionOnProduct.cshtml
@@ -1,10 +1,10 @@
@model ProductAskQuestionSimpleModel
-<input value="@Model.Id" type="hidden" id="AskQuestionProductId" name="AskQuestionProductId" />
+<input value="@Model.Id" type="hidden" id="AskQuestionProductId" ref="AskQuestionProductId" name="AskQuestionProductId" />
<div id="contact-us-product">
<fieldset class="form-group">
<validation-provider tag="div" rules="required|email" name="AskQuestionEmail" v-slot="{ errors, classes }">
<label asp-for="AskQuestionEmail" class="col-form-label">@Loc["Products.AskQuestion.Email"]:</label>
- <input asp-for="AskQuestionEmail" v-model="askquestion.AskQuestionEmail" placeholder="@Loc["Products.AskQuestion.Email.Hint"]" v-bind:class="[classes , 'form-control ask-question-email']" />
+ <input asp-for="AskQuestionEmail" ref="AskQuestionEmail" v-model="askquestion.AskQuestionEmail" placeholder="@Loc["Products.AskQuestion.Email.Hint"]" v-bind:class="[classes , 'form-control ask-question-email']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="AskQuestionEmail"></span>
</validation-provider>
@@ -12,19 +12,19 @@
<fieldset class="form-group">
<validation-provider tag="div" rules="required" name="AskQuestionFullName" v-slot="{ errors, classes }">
<label asp-for="AskQuestionFullName" class="col-form-label">@Loc["Products.AskQuestion.FullName"]:</label>
- <input asp-for="AskQuestionFullName" v-model="askquestion.AskQuestionFullName" placeholder="@Loc["Products.AskQuestion.FullName.Hint"]" v-bind:class="[classes , 'form-control ask-question-fullname']" />
+ <input asp-for="AskQuestionFullName" ref="AskQuestionFullName" v-model="askquestion.AskQuestionFullName" placeholder="@Loc["Products.AskQuestion.FullName.Hint"]" v-bind:class="[classes , 'form-control ask-question-fullname']" />
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="AskQuestionFullName"></span>
</validation-provider>
</fieldset>
<fieldset class="form-group">
<label asp-for="AskQuestionPhone" class="col-form-label">@Loc["Products.AskQuestion.Phone"]:</label>
- <input asp-for="AskQuestionPhone" placeholder="@Loc["Products.AskQuestion.Phone.Hint"]" class="form-control ask-question-phone" />
+ <input asp-for="AskQuestionPhone" ref="AskQuestionPhone" placeholder="@Loc["Products.AskQuestion.Phone.Hint"]" class="form-control ask-question-phone" />
</fieldset>
<fieldset class="form-group">
<validation-provider tag="div" rules="required" name="AskQuestionMessage" v-slot="{ errors, classes }">
<label asp-for="AskQuestionMessage" class="col-form-label">@Loc["Products.AskQuestion.Message"]:</label>
- <textarea asp-for="AskQuestionMessage" v-model="askquestion.AskQuestionMessage" placeholder="@Loc["Products.AskQuestion.Message.Hint"]" v-bind:class="[classes , 'form-control ask-question-message']" rows="4"></textarea>
+ <textarea asp-for="AskQuestionMessage" ref="AskQuestionMessage" v-model="askquestion.AskQuestionMessage" placeholder="@Loc["Products.AskQuestion.Message.Hint"]" v-bind:class="[classes , 'form-control ask-question-message']" rows="4"></textarea>
<span class="field-validation-error">{{ errors[0] }}</span>
<span asp-validation-for="AskQuestionMessage"></span>
</validation-provider>
@@ -39,19 +39,60 @@
AskQuestionMessage: '@Html.Raw(Model.AskQuestionMessage)',
</text>
}
- })
+ }),
+ methods: {
+ sendContactUsForm(urladd) {
+
+ var bodyFormData = new FormData();
+ bodyFormData.append('AskQuestionEmail', vm.$refs.AskQuestionEmail.value);
+ bodyFormData.append('AskQuestionFullName', vm.$refs.AskQuestionFullName.value);
+ bodyFormData.append('AskQuestionPhone', vm.$refs.AskQuestionPhone.value);
+ bodyFormData.append('AskQuestionMessage', vm.$refs.AskQuestionMessage.value);
+ bodyFormData.append('Id', vm.$refs.AskQuestionProductId.value);
+ bodyFormData.append('__RequestVerificationToken', document.querySelector('.product-details-page input[name=__RequestVerificationToken]').value);
+ if (document.querySelector("#contact-us-product textarea[id^='g-recaptcha-response']")) {
+ bodyFormData.append('g-recaptcha-response-value', document.querySelector(".product-details-page textarea[id^='g-recaptcha-response']").value);
+ }
+
+ axios({
+ url: urladd,
+ data: bodyFormData,
+ method: 'post',
+ headers: { 'Content-Type': 'multipart/form-data' }
+ }).then(function (response) {
+ if (response.data.success) {
+ document.querySelector('.product-standard #contact-us-product').style.display = "none";
+ document.querySelector('.product-standard .product-contact-error').style.display = "none";
+ document.querySelector('.product-standard .product-contact-send').innerHTML = response.data.message;
+ document.querySelector('.product-standard .product-contact-send').style.display = "block";
+ }
+ else {
+ document.querySelector('.product-standard .product-contact-error').innerHTML = response.data.message;
+ document.querySelector('.product-standard .product-contact-error').style.display = "block";
+ }
+ }).catch(function (error) {
+ alert(error);
+ });
+ },
+ @if (Model.DisplayCaptcha) {
+ <text>
+ getCaptcha() {
+ var html = document.getElementById("captcha-box");
+ document.getElementById("captcha-place").prepend(html);
+ }
+ </text>
+ }
+ }
});
</script>
@if (Model.DisplayCaptcha)
{
- <div class="captcha-box">
- <captcha />
- </div>
+ <div id="captcha-place"></div>
}
<div class="buttons generalMarginSupporter pt-1 pb-1">
<input type="submit" name="send-email" class="btn btn-info send-ask-question-button"
- value="@Loc["Products.AskQuestion.Button"]" data-form="sendcontactusform('@Url.RouteUrl("AskQuestionOnProduct")')" />
+ value="@Loc["Products.AskQuestion.Button"]" data-form="askquestion.sendContactUsForm('@Url.RouteUrl("AskQuestionOnProduct")')" />
<span class="sr-only">@Loc["Products.AskQuestion.Button"]</span>
</div>
diff --git a/src/Web/Grand.Web/wwwroot/theme/script/public.common.js b/src/Web/Grand.Web/wwwroot/theme/script/public.common.js
index e66b3be78..c95394af6 100644
--- a/src/Web/Grand.Web/wwwroot/theme/script/public.common.js
+++ b/src/Web/Grand.Web/wwwroot/theme/script/public.common.js
@@ -297,74 +297,6 @@ function runScripts($container) {
seq(runList, scriptsDone)
}
-function sendcontactusform(urladd) {
- if (document.querySelector('#ModalQuickView') == null) {
- if (document.querySelector(".product-standard #product-details-form").checkValidity()) {
- var bodyFormData = new FormData();
- bodyFormData.append('AskQuestionEmail', document.querySelector('.product-standard #AskQuestionEmail').value);
- bodyFormData.append('AskQuestionFullName', document.querySelector('.product-standard #AskQuestionFullName').value);
- bodyFormData.append('AskQuestionPhone', document.querySelector('.product-standard #AskQuestionPhone').value);
- bodyFormData.append('AskQuestionMessage', document.querySelector('.product-standard #AskQuestionMessage').value);
- bodyFormData.append('Id', document.querySelector('.product-standard #AskQuestionProductId').value);
- bodyFormData.append('__RequestVerificationToken', document.querySelector('.product-standard input[name=__RequestVerificationToken]').value);
- if (document.querySelector(".product-standard textarea[id^='g-recaptcha-response']")) {
- bodyFormData.append('g-recaptcha-response-value', document.querySelector(".product-standard textarea[id^='g-recaptcha-response']").value);
- }
- axios({
- url: urladd,
- data: bodyFormData,
- method: 'post',
- headers: { 'Content-Type': 'multipart/form-data' }
- }).then(function (response) {
- if (response.data.success) {
- document.querySelector('.product-standard #contact-us-product').style.display = "none";
- document.querySelector('.product-standard .product-contact-error').style.display = "none";
- document.querySelector('.product-standard .product-contact-send').innerHTML = response.data.message;
- document.querySelector('.product-standard .product-contact-send').style.display = "block";
- }
- else {
- document.querySelector('.product-standard .product-contact-error').innerHTML = response.data.message;
- document.querySelector('.product-standard .product-contact-error').style.display = "block";
- }
- }).catch(function (error) {
- alert(error);
- });
- }
- } else {
- if (document.querySelector("#ModalQuickView #product-details-form").checkValidity()) {
- var bodyFormData = new FormData();
- bodyFormData.append('AskQuestionEmail', document.querySelector('#ModalQuickView #AskQuestionEmail').value);
- bodyFormData.append('AskQuestionFullName', document.querySelector('#ModalQuickView #AskQuestionFullName').value);
- bodyFormData.append('AskQuestionPhone', document.querySelector('#ModalQuickView #AskQuestionPhone').value);
- bodyFormData.append('AskQuestionMessage', document.querySelector('#ModalQuickView #AskQuestionMessage').value);
- bodyFormData.append('Id', document.querySelector('#ModalQuickView #AskQuestionProductId').value);
- bodyFormData.append('__RequestVerificationToken', document.querySelector('#ModalQuickView input[name=__RequestVerificationToken]').value);
- if (document.querySelector("#ModalQuickView textarea[id^='g-recaptcha-response']")) {
- bodyFormData.append('g-recaptcha-response-value', document.querySelector("#ModalQuickView textarea[id^='g-recaptcha-response']").value);
- }
- axios({
- url: urladd,
- data: bodyFormData,
- method: 'post',
- headers: { 'Content-Type': 'multipart/form-data' }
- }).then(function (response) {
- if (response.data.success) {
- document.querySelector('#ModalQuickView #contact-us-product').style.display = "none";
- document.querySelector('#ModalQuickView .product-contact-error').style.display = "none";
- document.querySelector('#ModalQuickView .product-contact-send').innerHTML = response.data.message;
- document.querySelector('#ModalQuickView .product-contact-send').style.display = "block";
- }
- else {
- document.querySelector('#ModalQuickView .product-contact-error').innerHTML = response.data.message;
- document.querySelector('#ModalQuickView .product-contact-error').style.display = "block";
- }
- }).catch(function (error) {
- alert(error);
- });
- }
- }
-}
-
function GetPrivacyPreference(href) {
axios({
url: href,