/// <summary>
            /// Validate CAPTCHA
            /// </summary>
            /// <param name="context">A context for action filters</param>
            /// <returns>True if CAPTCHA is valid; otherwise false</returns>
            protected bool ValidateCaptcha(ActionExecutingContext context)
            {
                var isValid = false;

                //get form values
                var captchaResponseValue = context.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
                var gCaptchaResponseValue = context.HttpContext.Request.Form[G_RESPONSE_FIELD_KEY];

                if (!StringValues.IsNullOrEmpty(captchaResponseValue) || !StringValues.IsNullOrEmpty(gCaptchaResponseValue))
                {
                    //validate request
                    try
                    {
                        var value = !StringValues.IsNullOrEmpty(captchaResponseValue) ? captchaResponseValue : gCaptchaResponseValue;
                        var response = _captchaHttpClient.ValidateCaptchaAsync(value).Result;
                        isValid = response.IsValid;
                    }
                    catch (Exception exception)
                    {
                        _logger.Error("Error occurred on CAPTCHA validation", exception, _workContext.CurrentCustomer);
                    }
                }

                return isValid;
            }
Exemplo n.º 2
0
            /// <summary>
            /// Called asynchronously before the action, after model binding is complete.
            /// </summary>
            /// <param name="context">A context for action filters</param>
            /// <returns>A task that represents the asynchronous operation</returns>
            private async Task ValidateCaptchaAsync(ActionExecutingContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                if (!await DataSettingsManager.IsDatabaseInstalledAsync())
                {
                    return;
                }

                //whether CAPTCHA is enabled
                if (_captchaSettings.Enabled && context.HttpContext?.Request != null)
                {
                    //push the validation result as an action parameter
                    var isValid = false;

                    //get form values
                    var captchaResponseValue  = context.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
                    var gCaptchaResponseValue = context.HttpContext.Request.Form[G_RESPONSE_FIELD_KEY];

                    if (!StringValues.IsNullOrEmpty(captchaResponseValue) || !StringValues.IsNullOrEmpty(gCaptchaResponseValue))
                    {
                        //validate request
                        try
                        {
                            var value    = !StringValues.IsNullOrEmpty(captchaResponseValue) ? captchaResponseValue : gCaptchaResponseValue;
                            var response = await _captchaHttpClient.ValidateCaptchaAsync(value);

                            switch (_captchaSettings.CaptchaType)
                            {
                            case CaptchaType.CheckBoxReCaptchaV2:
                                isValid = response.IsValid;
                                break;

                            case CaptchaType.ReCaptchaV3:
                                isValid = response.IsValid &&
                                          response.Action == context.RouteData.Values["action"].ToString() &&
                                          response.Score > _captchaSettings.ReCaptchaV3ScoreThreshold;
                                break;

                            default:
                                break;
                            }
                        }
                        catch (Exception exception)
                        {
                            await _logger.ErrorAsync("Error occurred on CAPTCHA validation", exception, await _workContext.GetCurrentCustomerAsync());
                        }
                    }

                    context.ActionArguments[_actionParameterName] = isValid;
                }
                else
                {
                    context.ActionArguments[_actionParameterName] = false;
                }
            }
Exemplo n.º 3
0
        public async Task <IActionResult> DisplayContactUs(ContactUsModel model)
        {
            var resultModel = new ContactUsResultModel();

            if (_captchaSettings.Enabled)
            {
                var gCaptchaResponseValue = model.GRecaptchaResponse;

                if (StringValues.IsNullOrEmpty(gCaptchaResponseValue))
                {
                    return(BadRequest());
                }

                var response = _captchaHttpClient.ValidateCaptchaAsync(gCaptchaResponseValue).Result;
                if (!response.IsValid)
                {
                    return(BadRequest());
                }
            }

            var account = await _emailAccountService.GetEmailAccountByIdAsync(_emailAccountSettings.DefaultEmailAccountId);

            var ccEmails = new List <string>(_contactUsWidgetSettings.AdditionalEmails.Split(','));

            var toAddress = "";

            if (model.SelectedStore == "Website")
            {
                toAddress = _settings.ContactUsEmail ?? "*****@*****.**";
            }
            else
            {
                var shop = _shopRepository.Table.Where(s => s.Name == model.SelectedStore).FirstOrDefault();
                toAddress = _shopAbcRepository.Table.Where(sabc => sabc.ShopId == shop.Id).FirstOrDefault().AbcEmail;
                ccEmails.Add(_settings.ContactUsEmail);
            }

            var subject = "Customer " + model.Reason + "- " + model.SelectedStore + "/" + model.Name + "  " + model.PhoneNumber;

            var body = string.Format(
                @"A request has been submitted with an inquiry from the Contact us page. <br/><br/>

                Customer Name: {0} <br/>
                Customer Email: {1} <br/>
                Customer Phone Number: {2} <br/>
                Store Location: {3} <br/>
                Comments: {4}", model.Name ?? "", model.Email ?? "", model.PhoneNumber ?? "", model.SelectedStore ?? "", model.Comments ?? "");

            if (_settings.IsEmailSubmissionSkipped)
            {
                await _logger.WarningAsync($"AbcContactUs: Email submission skipped - body: {body}");
            }
            else
            {
                await _emailSender.SendEmailAsync(account, subject, body, account.Email, account.DisplayName, toAddress, "", replyToAddress : model.Email, cc : ccEmails);
            }

            return(Content(""));
        }
Exemplo n.º 4
0
            /// <summary>
            /// Validate CAPTCHA
            /// </summary>
            /// <param name="context">A context for action filters</param>
            /// <returns>True if CAPTCHA is valid; otherwise false</returns>
            protected bool ValidateCaptcha(ActionExecutingContext context)
            {
                var isValid = false;

                //get form values
                var captchaResponseValue  = context.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
                var gCaptchaResponseValue = context.HttpContext.Request.Form[G_RESPONSE_FIELD_KEY];

                if (!StringValues.IsNullOrEmpty(captchaResponseValue) || !StringValues.IsNullOrEmpty(gCaptchaResponseValue))
                {
                    //validate request
                    try
                    {
                        var value    = !StringValues.IsNullOrEmpty(captchaResponseValue) ? captchaResponseValue : gCaptchaResponseValue;
                        var response = _captchaHttpClient.ValidateCaptchaAsync(value).Result;

                        switch (_captchaSettings.CaptchaType)
                        {
                        case CaptchaType.CheckBoxReCaptchaV2:
                            isValid = response.IsValid;
                            break;

                        case CaptchaType.ReCaptchaV3:
                            isValid = response.IsValid &&
                                      response.Action == context.RouteData.Values["action"].ToString() &&
                                      response.Score > _captchaSettings.ReCaptchaV3ScoreThreshold;
                            break;

                        default:
                            break;
                        }
                    }
                    catch (Exception exception)
                    {
                        _logger.Error("Error occurred on CAPTCHA validation", exception, _workContext.CurrentCustomer);
                    }
                }

                return(isValid);
            }