protected ReCaptchaValidator ValidateCaptcha(String response, String userIPAddress)
        {
            ReCaptchaValidator validator = new ReCaptchaValidator();

            validator.Validate(response, userIPAddress);
            return(validator);
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var reCaptchaPrivateKey = ConfigurationManager.AppSettings["reCaptcha_privateKey"];
            var reCaptchaResponse   = filterContext.HttpContext.Request.Form["g-recaptcha-response"];

            var validator         = new ReCaptchaValidator(reCaptchaPrivateKey);
            var validatorResponse = validator.Validate(reCaptchaResponse);

            if (!validatorResponse.Success)
            {
                filterContext.Controller.ViewData.ModelState.AddModelError("ErrorCodes", string.Join(",", validatorResponse.ErrorCodes));
            }
        }
Exemplo n.º 3
0
        public async Task <Result <bool> > SendEmailOrder([FromBody] EmailOrderManageModel model)
        {
            if (!Validate(model))
            {
                return(false);
            }

            if (!await _reCaptchaValidator.Validate(model.Token))
            {
                ModelState.AddModelError(string.Empty, ErrorMessagesLibrary.Data[ErrorMessagesLibrary.Keys.WrongCaptcha]);
                return(false);
            }

            var lookups = await _settingService.GetLookupsAsync(SettingConstants.EMAIL_ORDER_LOOKUP_NAMES.Split(','));

            var requestorsLookup   = lookups.FirstOrDefault(p => p.Name == SettingConstants.EMAIL_ORDER_REQUESTOR_LOOKUP_NAME);
            var reasonsLookup      = lookups.FirstOrDefault(p => p.Name == SettingConstants.EMAIL_ORDER_REASON_LOOKUP_NAME);
            var shippingTypeLookup = lookups.FirstOrDefault(p => p.Name == SettingConstants.EMAIL_ORDER_SHIPPING_TYPE_LOOKUP_NAME);

            if (model.IdEmailOrderShippingType != null &&
                model.IdEmailOrderShippingType.Value == (int)EmailOrderShippingType.WillCall)
            {
                model.Shipping.Address1 = null;
                model.Shipping.Address2 = null;
                model.Shipping.City     = null;
                model.Shipping.County   = null;
                model.Shipping.Country  = null;
                model.Shipping.Zip      = null;
                model.Shipping.Fax      = null;
                model.Shipping.Phone    = null;
            }

            var email = new EmailOrderEmail()
            {
                DateCreated    = DateTime.Now,
                DetailsOnEvent = model.DetailsOnEvent,
                Instuction     = model.Instuction,
                Requestor      = model.IdRequestor.HasValue ?
                                 requestorsLookup.LookupVariants.FirstOrDefault(p => p.Id == model.IdRequestor.Value)?.ValueVariant
                            : null,
                Reason = model.IdReason.HasValue ?
                         reasonsLookup.LookupVariants.FirstOrDefault(p => p.Id == model.IdReason.Value)?.ValueVariant
                            : null,
                EmailOrderShippingType = model.IdEmailOrderShippingType.HasValue ?
                                         shippingTypeLookup.LookupVariants.FirstOrDefault(p => p.Id == model.IdEmailOrderShippingType.Value)?.ValueVariant
                            : null,
                Shipping = new AddressBaseModel()
                {
                    Company                                                             = model.Shipping.Company,
                    FirstName                                                           = model.Shipping.FirstName,
                    LastName                                                            = model.Shipping.LastName,
                    Address1                                                            = model.Shipping.Address1,
                    Address2                                                            = model.Shipping.Address2,
                    City                                                                = model.Shipping.City,
                    County                                                              = model.Shipping.County,
                    Country                                                             = model.Shipping.Country != null?_countryNameCodeResolver.GetCountryName(model.Shipping.Country.Id) : null,
                                                          State                         = model.Shipping.Country != null?_countryNameCodeResolver.GetStateName(model.Shipping.Country.Id, model.Shipping.State) : null,
                                                                                  Zip   = model.Shipping.Zip,
                                                                                  Fax   = model.Shipping.Fax,
                                                                                  Phone = model.Shipping.Phone,
                }
            };

            email.DateCreatedDatePart = email.DateCreated.ToString("MM/dd/yyyy");
            email.DateCreatedTimePart = email.DateCreated.ToString("hh:mm tt");
            email.Skus = model.SkuOrdereds?.Where(p => !string.IsNullOrEmpty(p.Code) && p.QTY.HasValue && p.Price.HasValue).Select(p => new EmailOrderSku()
            {
                Code  = p.Code,
                QTY   = p.QTY.Value,
                Price = p.Price.Value
            }).ToList() ?? new List <EmailOrderSku>();


            await _notificationService.SendEmailOrderEmailAsync(email);

            return(true);
        }
Exemplo n.º 4
0
 public async void Validate_IPArgumentNull_ShouldThrowArgumentNullException()
 {
     IReCaptchaValidator validator = new ReCaptchaValidator("site_key", "secret_key");
     await Assert.ThrowsAsync <ArgumentNullException>(() => validator.Validate("code", null));
 }
Exemplo n.º 5
0
 public async void Validate_CodeArgumentNullOrEmpty_ShouldThrowArgumentException(string code)
 {
     IReCaptchaValidator validator = new ReCaptchaValidator("site_key", "secret_key");
     await Assert.ThrowsAsync <ArgumentException>(() => validator.Validate(code, IPAddress.Any));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Event method sets frame content version and parameters
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            bool blnIsSpanish = false;

            confirmDiv.Visible = false;
            formDiv.Visible    = true;

            this.Header.Title = "E-Mail This Page - National Cancer Institute";

            if (this.DisplayLanguage == DisplayLanguage.Spanish)
            {
                this.Header.Title = "Enviar esta p&aacute;gina por correo electr&oacute;nico - Instituto Nacional del C&amp;aacute;ncer";
                strSendtoEmail    = "Compartir este enlace con&nbsp;&nbsp;<br>(dirección de correo electrónico)&nbsp;&nbsp;<br>(Send to this e-mail)&nbsp;&nbsp;";
                strFromEmail      = "Su dirección de correo electrónico&nbsp;&nbsp;<br>(Your e-mail)&nbsp;&nbsp;";
                strName           = "Su nombre&nbsp;&nbsp;<br>(Your name)&nbsp;&nbsp;";
                strSend           = "Enviar/Send";
                blnIsSpanish      = true;
            }



            if (!this.IsPostBack)
            {
                //assign passed in variables to controls
                Document.Value = HttpUtility.UrlEncode(Strings.IfNull(Strings.Clean(Request.Params["title"]), ""));
                Title.Text     = HttpUtility.UrlDecode(Document.Value).Replace("__tm;", "&#153;");
                Url.Value      = Strings.IfNull(Strings.Clean(Request.QueryString["docurl"]), "").Replace("__amp;", "&");
                //if(Url.Value.StartsWith("/"))
                //{
                //    Url.Value = Request.Url.GetLeftPart(System.UriPartial.Authority) + Url.Value;
                //}
            }
            else
            {
                //Validate required controls
                if (!CancerGov.Web.EmailSyntaxValidator.Valid(To.Value, true))
                {
                    To.Value = "";
                }

                if (!CancerGov.Web.EmailSyntaxValidator.Valid(From.Value, true))
                {
                    From.Value = "";
                }

                toValid.Validate();
                fromValid.Validate();
                revFromName.Validate();
                string EncodedResponse = Request.Form["g-recaptcha-response"];
                reCaptchaValidator.Validate(EncodedResponse, Request.UserHostAddress);

                //Send Email Required Controls Are Valid
                if (toValid.IsValid && fromValid.IsValid && revFromName.IsValid && reCaptchaValidator.Success)
                {
                    confirmDiv.Visible = true;
                    formDiv.Visible    = false;

                    if (HashMaster.SaltedHashCompare(HttpUtility.UrlDecode(Document.Value) + Strings.IfNull(Strings.Clean(Request.QueryString["docurl"]), "").Replace("__amp;", "&"),
                                                     HttpUtility.UrlEncode(Strings.IfNull(Strings.Clean(Request.Params["a"]), "")),
                                                     HttpUtility.UrlEncode(Strings.IfNull(Strings.Clean(Request.Params["b"]), ""))))
                    {
                        //Create document hyperlink
                        if (Url.Value.StartsWith("/"))
                        {
                            Url.Value = Request.Url.GetLeftPart(System.UriPartial.Authority) + Url.Value;
                        }
                        //HtmlAnchor docLink = new HtmlAnchor(Url.Value, HttpUtility.UrlDecode(Strings.IfNull(Strings.Clean(Document.Value), Url.Value)));


                        //Create mail
                        MailMessage mailMsg = new MailMessage(From.Value, To.Value);
                        mailMsg.IsBodyHtml = true;

                        //Determine where the popup was invoked.
                        EmailPopupInvokedBy sourcePage = DeterminePopupSource();

                        switch (sourcePage)
                        {
                        case EmailPopupInvokedBy.ClinicalTrialSearchResults:
                            //Currently no Spanish for Clinical Trials Search
                            mailMsg.Subject = "Clinical Trials from the National Cancer Institute Web site";
                            mailMsg.Body    = "<html><head></head><body>The following link from the National Cancer Institute's (NCI's) Web site has been sent to you by " + Strings.IfNull(Strings.Clean(FromName.Value), "a colleague") + ":<P>Clinical Trials Search Results<P><a href=\"" + Url.Value + "\">" + Url.Value + "</a><p>You can find educational materials about clinical trials on NCI’s Web site at <a href=\"http://www.cancer.gov/clinicaltrials\">http://www.cancer.gov/clinicaltrials</a>.  NCI's Web site, <a href=\"http://www.cancer.gov\">www.cancer.gov</a>, contains comprehensive information about cancer causes and prevention, screening and diagnosis, treatment and survivorship; clinical trials; statistics; funding, training and employment opportunities; and the institute and its programs.<p>You can also get cancer information online through the LiveHelp instant messaging service at <a href=\"http://livehelp.cancer.gov\">http://livehelp.cancer.gov</a>.  If you live in the United States, you may call the NCI's Cancer Information Service toll-free at 1-800-4-CANCER (1-800-422-6237) for cancer information in English and Spanish.</body></html>";
                            break;

                        case EmailPopupInvokedBy.ClinicalTrialPrintableSearchResults:
                            //Currently no Spanish for Clinical Trials Search
                            mailMsg.Subject = "Clinical Trials from the National Cancer Institute Web site";
                            mailMsg.Body    = "<html><head></head><body>The following link from the National Cancer Institute's (NCI's) Web site has been sent to you by " + Strings.IfNull(Strings.Clean(FromName.Value), "a colleague") + ":<P>Print-Friendly Clinical Trial Descriptions<P><a href=\"" + Url.Value + "\">" + Url.Value + "</a><p>Please note that the URL will expire after 90 days.<p>You can find educational materials about clinical trials on NCI’s Web site at <a href=\"http://www.cancer.gov/clinicaltrials\">http://www.cancer.gov/clinicaltrials</a>.  NCI's Web site, <a href=\"http://www.cancer.gov\">www.cancer.gov</a>, contains comprehensive information about cancer causes and prevention, screening and diagnosis, treatment and survivorship; clinical trials; statistics; funding, training and employment opportunities; and the institute and its programs.<p>You can also get cancer information online through the LiveHelp instant messaging service at <a href=\"http://livehelp.cancer.gov\">http://livehelp.cancer.gov</a>.  If you live in the United States, you may call the NCI's Cancer Information Service toll-free at 1-800-4-CANCER (1-800-422-6237) for cancer information in English and Spanish.</body></html>";
                            break;

                        case EmailPopupInvokedBy.Unspecified:
                        default:
                            if (blnIsSpanish)
                            {
                                mailMsg.Subject = "Información del portal de Internet del Instituto Nacional del Cáncer";
                                mailMsg.Body    = "<html><head></head><body>El siguiente enlace al portal de Internet del Instituto Nacional del Cáncer (NCI, por sus siglas en inglés) le ha sido enviado por " + Strings.IfNull(Strings.Clean(FromName.Value), "un colega") + ":<P>" + HttpUtility.UrlDecode(Title.Text) + "<BR><a href=\"" + Url.Value + "\">" + Url.Value + "</a><p>El portal del Instituto Nacional del Cáncer en la Web, <a href=\"http://www.cancer.gov\">www.cancer.gov</a>, contiene información completa sobre las causas y prevención, exámenes selectivos de detección y diagnóstico, tratamiento y supervivencia al cáncer, así como sobre estudios clínicos, estadísticas, financiamiento, capacitación y oportunidad de empleo, y sobre el Instituto y sus programas.  Usted puede también obtener información en línea por medio del servicio de mensajería instantánea <i>LiveHelp</i> en <a href=\"http://livehelp.cancer.gov\">http://livehelp.cancer.gov</a>. Si usted vive en los Estados Unidos, usted puede llamar gratis al Servicio de Información sobre el Cáncer del Instituto Nacional del Cáncer al 1-800-4-CANCER (1-800-422-6237) para información del cáncer en inglés y en español.</body></html>";
                            }
                            else
                            {
                                mailMsg.Subject = "Information from the National Cancer Institute Web Site";
                                mailMsg.Body    = "<html><head></head><body>The following link from the National Cancer Institute's (NCI's) Web site has been sent to you by " + Strings.IfNull(Strings.Clean(FromName.Value), "a colleague") + ":<P>" + HttpUtility.UrlDecode(Title.Text) + "<BR><a href=\"" + Url.Value + "\">" + Url.Value + "</a><p>NCI's Web site, <a href=\"http://www.cancer.gov\">www.cancer.gov</a>, contains comprehensive information about cancer causes and prevention, screening and diagnosis, treatment and survivorship; clinical trials; statistics; funding, training and employment opportunities; and the institute and its programs. You can also get cancer information online through the LiveHelp instant messaging service at <a href=\"http://livehelp.cancer.gov\">http://livehelp.cancer.gov</a>.  If you live in the United States, you may call the NCI's Cancer Information Service toll-free at 1-800-4-CANCER (1-800-422-6237) for cancer information in English and Spanish.</body></html>";
                            }
                            break;
                        }

                        //Send mail
                        //SmtpMail.Send(mailMsg);
                        SmtpClient sc = new SmtpClient();
                        sc.Send(mailMsg);

                        //show confirmation message
                        strConfirm = "<br><br>The link has been sent.<br>Thank you for using the NCI's Web site.";
                        if (blnIsSpanish)
                        {
                            strConfirm = "<br><br>El enlace ha sido enviado.<br>¡Gracias por visitar el portal de Internet del NCI.<br><br>(The link has been sent.<br>Thank you for using the NCI's Web site.)";
                        }
                    }
                    else
                    {
                        //show confirmation message
                        strConfirm = "<br><br>Unable to send link.<br>Please close window and try again.";
                        if (blnIsSpanish)
                        {
                            // Google translation TEMPORARY - LH
                            strConfirm = "<br><br>No se puede enviar enlace.<br>Por favor, cierre la ventana y vuelva a intentarlo<br><br>(Unable to send link.<br>Please close window and try again.)";
                        }
                    }
                }
            }
        }