示例#1
0
        public ActionResult SubmitForm(Contact model)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (string.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("reCAPTCHA", "Please complete the reCAPTCHA");
                return(CurrentUmbracoPage());
            }
            else
            {
                RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();
                if (recaptchaResult != RecaptchaVerificationResult.Success)
                {
                    ModelState.AddModelError("reCAPTCHA", "The reCAPTCHA is incorrect");
                    return(CurrentUmbracoPage());
                }
            }

            if (ModelState.IsValid)
            {
                //Process the valid form

                SendEmail(model);
                TempData["ContactSuccess"] = true;
                return(RedirectToCurrentUmbracoPage());
            }
            return(CurrentUmbracoPage());
        }
示例#2
0
        public async Task <ActionResult> Index(Socioboard.Helper.Enterprise ent)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            string ret;

            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Captcha answer cannot be empty.");
                //return View(model);
                return(View());
            }

            RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError("", "Incorrect captcha answer.");
                ViewBag.AlertMsg = "error";
                return(RedirectToAction("Enterprise", "Versions", new { hint = "error" }));
            }
            else
            {
                Api.MailSender.MailSender ApiobjMailSender = new Api.MailSender.MailSender();
                ret = ApiobjMailSender.SendEnterpriseMail(ent.Name, ent.Designation, ent.ContactEmailId, ent.Location, ent.Company, ent.CompanyWebsite, ent.Message, ent.Phone);

                return(RedirectToAction("Enterprise", "Versions", new { hint = "success" }));
                //return Content(ret);
                //return View();
            }


            // return View(model);
            //return View();
        }
 public async Task<CaptchaOutput> ValidateCaptcha(CaptchaData captchaData)
 {
     CaptchaOutput result = new CaptchaOutput()
     {
         Status = false,
         Msg = ""
     };
     RecaptchaVerificationHelper verify = new RecaptchaVerificationHelper()
     {
         Challenge = captchaData.CaptchaChallenge,
         Response = captchaData.CaptchaResponse,
         PrivateKey = "6LeX2cgSAAAAAKkTWQSP6lO7xYsq_v4UF1BM_iCi",
         UserHostAddress = captchaData.UserHostAddress,
         UseSsl = false
     };
     RecaptchaVerificationResult response = await verify.VerifyRecaptchaResponseTaskAsync();
     if (response == RecaptchaVerificationResult.Success)
     {
         result.Status = true;
     }
     else
     {
         result.Status = false;
         result.Msg = "Mã bảo vệ chưa đúng, bạn vui lòng nhập lại!";
     }
     result.ClientId = string.IsNullOrEmpty(captchaData.ClientId) ? Guid.NewGuid().ToString("n") : captchaData.ClientId;
     result.AccessToken = string.Empty;
     await Task.Delay(1);
     return result;
 }
示例#4
0
        protected void ASPxButtonLogin_Click(object sender, EventArgs e)
        {
            Page.Validate();

            if (!Page.IsValid)
            {
                return;
            }


            if (string.IsNullOrEmpty(recaptchaUserValue.Value))
            {
                Msg.Text = "Error en los datos de seguridad, vuelva a recargar la página.";
                return;
            }


            var Recaptchav3 = new RecaptchaVerificationHelper();

            // If your site is behind CloudFlare, be sure you're suing the CF-Connecting-IP header value instead:
            // https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers

            RecaptchaVerificationResult recaptchaResult = Recaptchav3.VerifyRecaptchav3Response(
                Global.Configuration.Security.Google.Recaptcha.v3.GetGoogleRecaptchaSecretKey()
                , Global.Configuration.Security.Google.Recaptcha.v3.GetGoogleRecaptchaWebsiteKey()
                , Request.UserHostAddress
                , recaptchaUserValue.Value
                );

            if (recaptchaResult == RecaptchaVerificationResult.Success)
            {
                //divMessage.InnerHtml = "Score: " + Recaptchav3.Score;
                decimal?minScore = new decimal(0.6);
                if (Recaptchav3.Score < minScore)
                {
                    Response.Redirect("~/Captcha.aspx", true);
                }


                //create session
                // Global.Sessions.UserCreateSession();

                if (UsernameTextbox.Text.Equals(ConfigurationManager.AppSettings["Authentication:Credentials.User.Login"].ToString(), StringComparison.InvariantCulture) &&
                    PasswordTextbox.Text.Equals(ConfigurationManager.AppSettings["Authentication:Credentials.User.Password"].ToString(), StringComparison.InvariantCulture))
                {
                    Session["User.UserID"] = UsernameTextbox.Text;
                    Session.Timeout        = 60;
                    Response.Redirect("~/Admin/Main.aspx");
                }
                else
                {
                    Msg.Text = "Login failed. Please check your user name and password and try again.";
                }
            }
            else
            {
                Msg.Text = "Existe un problema para validar la seguridad, intente mas tarde o por favor contacte a soporte técnico.";
                return;
            }
        }
示例#5
0
        public async Task <ActionResult> Feedback(FeedBackModel model)
        {
            try
            {
                RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

                if (String.IsNullOrEmpty(recaptchaHelper.Response))
                {
                    TempData["FeedbackStatus"]  = false;
                    TempData["FeedbackMessage"] = "Vui lòng nhập mã bảo mật bên dưới.";
                    return(Redirect(Request.UrlReferrer.AbsoluteUri));
                }

                RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();

                if (recaptchaResult != RecaptchaVerificationResult.Success)
                {
                    TempData["FeedbackStatus"]  = false;
                    TempData["FeedbackMessage"] = "Vui lòng nhập lại mã bảo mật bên dưới.";
                    return(Redirect(Request.UrlReferrer.AbsoluteUri));
                }
                TempData["FeedbackStatus"] = model.InsertNewFeedback();
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
            catch (Exception exception)
            {
                LoggingUtil.LogException(exception);
                return(RedirectToAction(Constants.SystemFailureHomeAction, Constants.ErrorController));
            }
        }
        public ActionResult Index(ContactModel contactModel)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Captcha answer cannot be empty.");
                return(Index());
            }

            if (ModelState.IsValid)
            {
                contactModel.Brand = this.CurrentBrand;
                var ok = ContactManager.Create(contactModel);
                if (ok)
                {
                    return(RedirectToAction("ThankYou"));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
示例#7
0
        public async Task <ActionResult> Login(LoginViewModel vm, string returnUrl)
        {
            #region Recaptcha
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();
            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Captcha answer cannot be empty.");
                return(View(vm));
            }
            RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError("", "Incorrect captcha answer.");
            }
            #endregion

            if (!ModelState.IsValid)
            {
                return(View(vm));
            }


            var user = this._userSertvice.Verify(vm.EmailAddress, vm.Password);

            if (user != null)
            {
                this.SignIn(user, true);
                return(RedirectToLocal(returnUrl).Success(string.Format("Welcome back {0}!", user.Fullname)));
            }

            ModelState.AddModelError("", "Invalid email or password.");
            return(View(vm));
        }
示例#8
0
        public ActionResult CreateByTopic(int id, [Bind(Include = "QuoteId,TopicId,QuoteText,QuoteAuthor,QuotePassword")] Quotes quotes)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (string.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Shit's fried mate");
            }
            RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError("", "Incorrect captcha answer.");
            }
            quotes.TopicId = id;
            if (ModelState.IsValid)
            {
                db.Quotes.Add(quotes);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TopicId = new SelectList(db.Topics, "TopicId", "TopicName", quotes.TopicId);
            return(View(quotes));
        }
示例#9
0
        public async Task <ActionResult> Login(string email, string password)
        {
            Login login = new Login();

            try
            {
                if (login.RecaptchaTime())
                {
                    RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();
                    if (String.IsNullOrEmpty(recaptchaHelper.Response))
                    {
                        throw new CustomException.EmptyRecaptcha();
                    }
                    RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();

                    if (recaptchaResult != RecaptchaVerificationResult.Success)
                    {
                        throw new CustomException.Recaptcha();
                    }
                }
                login.LoginUser(email, password);
            }

            catch (Exception ex)
            {
                if (ex is CustomException.EmptyRecaptcha || ex is CustomException.Recaptcha)
                {
                    login.Error = ex.Message;
                }
                return(View(login));
            }
            return(Redirect("/home/index"));
        }
示例#10
0
        public async Task <ActionResult> Register(string email, string password1, string password2, string name, string company)
        {
            RegisterUser userToRegister = new RegisterUser();

            try
            {
                userToRegister.Setup(email, password1, password2, name, company);
                RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();
                if (String.IsNullOrEmpty(recaptchaHelper.Response))
                {
                    throw new CustomException.EmptyRecaptcha();
                }
                RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();

                if (recaptchaResult != RecaptchaVerificationResult.Success)
                {
                    throw new CustomException.Recaptcha();
                }
                userToRegister.Save();
                return(View());
            }
            catch (Exception ex)
            {
                if (ex is CustomException.EmptyRecaptcha || ex is CustomException.Recaptcha)
                {
                    userToRegister.Error = ex.Message;
                }
                return(View(userToRegister));
            }
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!string.IsNullOrEmpty(_publicKey) && !string.IsNullOrEmpty(_privateKey))
            {
                var localizedResourceService = HostContainer.GetInstance <ILocalizedResourceService>();

                var controller = (Controller)HttpContext.Current.Items[FrameworkConstants.EzCurrentController];
                RecaptchaVerificationHelper recaptchaHelper = controller.GetRecaptchaVerificationHelper(_privateKey);

                if (string.IsNullOrEmpty(recaptchaHelper.Response))
                {
                    filterContext.Controller.ViewData.ModelState.AddModelError(Name,
                                                                               localizedResourceService.T("CaptchaValidation_Message_EmptyCaptcha"));
                }
                RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();

                if (recaptchaResult != RecaptchaVerificationResult.Success)
                {
                    filterContext.Controller.ViewData.ModelState.AddModelError(Name,
                                                                               localizedResourceService.T("CaptchaValidation_Message_InvalidCaptchaAnswer"));
                }
            }

            base.OnActionExecuting(filterContext);
        }
示例#12
0
        public async Task <ContentResult> New(string name, string email, string comment, int ignorecaptcha = 0)
        {
            try
            {
                if (ignorecaptcha != 1)
                {
                    RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();


                    if (String.IsNullOrEmpty(recaptchaHelper.Response))
                    {
                        ModelState.AddModelError("", "Captcha answer cannot be empty.");
                        return(Content("{\"success\":false}", "text/plain"));
                    }

                    RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();

                    if (recaptchaResult != RecaptchaVerificationResult.Success)
                    {
                        ModelState.AddModelError("", "Incorrect captcha answer.");
                        return(Content("{\"success\":false}", "text/plain"));
                    }
                }
                Random       rnd  = new Random();
                int          id   = rnd.Next(10000, 20000);
                StreamReader w    = new StreamReader(HostingEnvironment.MapPath("~/email.html"), true);
                var          body = await w.ReadToEndAsync();

                body = body.Replace("{name}", name).Replace("{number}", id.ToString()).Replace("{message}", comment);
                var message = new MailMessage();
                message.To.Add(new MailAddress("*****@*****.**")); // replace with valid value
                message.To.Add(new MailAddress(email));
                message.From = new MailAddress("*****@*****.**");   // replace with valid value
                message.ReplyToList.Add(email);
                message.Subject    = "Support Request #" + id;
                message.Body       = body;
                message.IsBodyHtml = true;

                using (var smtp = new SmtpClient())
                {
                    var credential = new NetworkCredential
                    {
                        UserName = "******", // replace with valid value
                        Password = "******"                // replace with valid value
                    };
                    smtp.Credentials = credential;
                    smtp.Host        = "smtp.epicapps.com.br";
                    smtp.Port        = 587;
                    smtp.EnableSsl   = false;
                    await smtp.SendMailAsync(message);
                }
            }
            catch (Exception e)
            {
                return(Content("{\"success\":false, \"message\": " + e.Message + e.ToString() + "}", "text/plain"));
            }
            return(Content("{\"success\":true}", "text/plain"));
        }
示例#13
0
        public ActionResult SubmitContactForm(ContactFormModel model) //Use ActionResult to handle the user interaction
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            //Check if reCAPTCHA has a result
            if (string.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("reCAPTCHA", "Please complete the reCAPTCHA");
                return(CurrentUmbracoPage());

                /* If it's an USkinned Umbraco Site:
                 *  return JavaScript("$('#recaptchaErrorMsg').show();$('#recaptchaErrorMsg').html('The reCAPTCHA field is required.');");
                 */
            }
            else
            {
                //Check if reCAPTCHA has a success result
                RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();
                if (recaptchaResult != RecaptchaVerificationResult.Success)
                {
                    ModelState.AddModelError("reCAPTCHA", "The reCAPTCHA is incorrect!");
                    return(CurrentUmbracoPage());

                    /* If it's an USkinned Umbraco Site:
                     *  return JavaScript("$('#recaptchaFailMsg').show();$('#recaptcahFailMsg').html('The reCAPTCHA is incorrect!');");
                     */
                }
            }

            //Check if the data posted is valid
            if (!ModelState.IsValid)
            {
                return(CurrentUmbracoPage());

                /* If it's an USkinned Umbraco Site:
                 *  return JavaScript(String.Format("$(ContactError{0}).show();$(ContactError{0}).html('{1}');", model.CurrentNodeID, HttpUtility.JavaScriptStringEncode(umbraco.library.GetDictionaryItem("USN Contact Form General Error"))));
                 */
            }

            string managerEmail = CurrentPage.HasValue("notifyEmail") ? CurrentPage.GetPropertyValue <string>("notifyEmail") : string.Empty;

            //Send email to manager
            SendNotificationToManager(model, managerEmail);

            //Send an auto replied email back to the clients
            SendAutoResponder(model);

            //Check if redirectionPage Url is empty
            var redirectionPage = CurrentPage.GetPropertyValue <Link>("redirection");

            //If it is, then redirect page to the Home page
            if (string.IsNullOrWhiteSpace(redirectionPage?.Url))
            {
                return(this.RedirectToUmbracoPage(CurrentPage.Site()));
            }
            //Otherwise, redirect it to the redirection page
            return(this.Redirect(redirectionPage.Url));
        }
示例#14
0
        /// <summary>
        /// Calls the OnLoad method of the parent class <see cref="System.Web.UI.WebControls.WebControl"/> and initializes the internal state of the <see cref="Recaptcha"/> control for verification of the user's response to the recaptcha challenge.
        /// </summary>
        /// <param name="e">The <see cref="EventArgs"/> object passed to the Load event of the control.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (this.Page.IsPostBack)
            {
                _verificationHelper = new RecaptchaVerificationHelper(this.PrivateKey);
            }
        }
示例#15
0
        /// <summary>
        /// Verifies the user's answer to the recaptcha challenge.
        /// </summary>
        /// <returns>Returns the verification result as <see cref="RecaptchaVerificationResult"/> enum value.</returns>
        ///<exception cref="InvalidOperationException">The private key is null or empty.</exception>
        ///<exception cref="System.Net.WebException">The time-out period for the recaptcha verification request expired.</exception>
        public RecaptchaVerificationResult Verify()
        {
            if (_verificationHelper == null)
            {
                _verificationHelper = new RecaptchaVerificationHelper(this.PrivateKey);
            }

            return(_verificationHelper.VerifyRecaptchaResponse());
        }
示例#16
0
        /// <summary>
        /// Verifies the user's answer to the recaptcha challenge.
        /// </summary>
        /// <returns>Returns the verification result as <see cref="RecaptchaVerificationResult"/> enum value.</returns>
        ///<exception cref="InvalidOperationException">The private key is null or empty.</exception>
        ///<exception cref="System.Net.WebException">The time-out period for the recaptcha verification request expired.</exception>
        public Task <RecaptchaVerificationResult> VerifyTaskAsync()
        {
            if (_verificationHelper == null)
            {
                _verificationHelper = new RecaptchaVerificationHelper(this.PrivateKey);
            }

            return(_verificationHelper.VerifyRecaptchaResponseTaskAsync());
        }
示例#17
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (string.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("reCAPTCHA", "Please complete the reCAPTCHA");
                return(View(model));
            }
            else
            {
                RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();
                if (recaptchaResult != RecaptchaVerificationResult.Success)
                {
                    ModelState.AddModelError("reCAPTCHA", "The reCAPTCHA is incorrect");
                    return(View(model));
                }
            }

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Username, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                var lpUser = new LPUser();
                lpUser.Email    = model.Email;
                lpUser.Username = model.Username;
                //Used for testing
                //string[] splitstring = model.Email.Split('@');
                //lpUser.Username = splitstring[0];
                if (result.Succeeded)
                {
                    db.LPUsers.Add(lpUser);
                    db.SaveChanges();
                    CreateProfile(model.Email);
                    System.Diagnostics.Debug.WriteLine("Registered");
                    //  Comment the following line to prevent log in until the user is confirmed.
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account");

                    ViewBag.Message = "Check your email and confirm your account, you must be confirmed "
                                      + "before you can log in.";

                    //Call the ActionResult method that creates an LPUser
                    //return RedirectToAction("LPUserCreate", "Home", new { Email = model.Email });
                    return(View("Info"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (string.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("reCAPTCHA", "Please complete the reCAPTCHA");
                // If we got this far, something failed, redisplay form
                return(View(model));
            }
            else
            {
                RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();
                if (recaptchaResult != RecaptchaVerificationResult.Success)
                {
                    ModelState.AddModelError("reCAPTCHA", "The reCAPTCHA is incorrect");
                    // If we got this far, something failed, redisplay form
                    return(View(model));
                }
            }
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    //Replace this with Repository Pattern!!
                    CompanionContext db       = new CompanionContext();
                    CompanionUser    compUser = new CompanionUser();
                    compUser.ASPIdentityID = user.Id;
                    compUser.Email         = user.Email;
                    db.CompanionUsers.Add(compUser);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#19
0
        public ActionResult Create(EditOrderViewModel model)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (string.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Captcha відповідь не може бути пустою.");
                return(View("Edit", model));
            }

            RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError("", "Невірна captcha відповідь.");
                return(View("Edit", model));
            }

            HttpCookie consumerBasketRawDataCookie = Request.Cookies["ConsumerBasket"];

            if (consumerBasketRawDataCookie == null)
            {
                ModelState.AddModelError("", "Не вибрано жодного товару для покупки");
            }

            if (ModelState.IsValid)
            {
                List <ProductInBasketViewModel> productInBasketViewModels = JsonConvert.DeserializeObject <List <ProductInBasketViewModel> >(
                    HttpContext.Server.UrlDecode(consumerBasketRawDataCookie.Value));

                Order order = _ordersBL.CreateOrder(new CreateOrderQuery
                {
                    Person = new CreateOrderQuery.AddPersonQuery
                    {
                        Email       = model.Email,
                        MiddleName  = model.MiddleName,
                        LastName    = model.LastName,
                        PhoneNumber = model.PhoneNumber,
                        FirstName   = model.FirstName
                    },
                    OrderedProducts = new List <CreateOrderQuery.AddOrderedProductQuery>(
                        productInBasketViewModels.Select(
                            p => new CreateOrderQuery.AddOrderedProductQuery
                    {
                        ProductId = p.Id,
                        Quantity  = p.Quantity
                    }).ToList()),
                    AdditionalComment = model.AdditionalComment
                });
                TempData[Constants.TempDataKeys.ORDER_ID] = order.Id;
                return(RedirectToAction("OrderDetails", new { orderId = order.Id }));
            }

            return(View("Edit", model));
        }
示例#20
0
        public ActionResult RateHospital(int id = 0, int score = 0)
        {
            try
            {
                if (Session["RATING_TIME"] == null)
                {
                    Session["RATING_TIME"] = 0;
                }

                int ratingTime = (int)Session["RATING_TIME"];
                Session["RATING_TIME"] = ++ratingTime;

                if (ratingTime > 3)
                {
                    RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

                    if (String.IsNullOrEmpty(recaptchaHelper.Response))
                    {
                        TempData["RateActionStatus"]  = false;
                        TempData["RateActionMessage"] = "Vui lòng nhập mã bảo mật bên dưới.";

                        return(RedirectToAction(Constants.HospitalAction, Constants.HomeController, new { hospitalId = id, redirect = "yes" }));
                    }

                    RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();

                    if (recaptchaResult != RecaptchaVerificationResult.Success)
                    {
                        TempData["RateActionStatus"]  = false;
                        TempData["RateActionMessage"] = "Vui lòng nhập lại mã bảo mật bên dưới.";

                        return(RedirectToAction(Constants.HospitalAction, Constants.HomeController, new { hospitalId = id, redirect = "yes" }));
                    }
                }

                string email = User.Identity.Name.Split(Char.Parse(Constants.Minus))[0];

                int userId = AccountModel.LoadUserIdByEmail(email);

                bool check = HomeModel.RateHospital(userId, id, score);
                if (!check)
                {
                    TempData["RateActionStatus"]  = false;
                    TempData["RateActionMessage"] = "Vui lòng thử lại sau ít phút.";
                }
                TempData["RateActionStatus"] = true;
                return(RedirectToAction(Constants.HospitalAction, Constants.HomeController, new { hospitalId = id, redirect = "yes" }));
            }
            catch (Exception exception)
            {
                LoggingUtil.LogException(exception);
                return(RedirectToAction(Constants.SystemFailureHomeAction, Constants.ErrorController));
            }
        }
示例#21
0
        public bool CheckCaptcha(RecaptchaVerificationHelper recaptchaHelper, ref string errore)
        {
            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                errore = App_GlobalResources.ErrorResource.ContactsCaptchaEmpty;
                return(false);
            }
            RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                errore = App_GlobalResources.ErrorResource.ContactsCaptchaError;
                return(false);
            }
            return(true);
        }
示例#22
0
        private async Task ReCapchaVerification()
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (string.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Click the thing that says 'I'm not a robot' (unless you are actually a robot, in which case go away)");
                return;
            }

            RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError("", "Google says you're a bot. Sorry (notsorry)");
            }
        }
        protected void BootstrapButtonLogin_Click(object sender, EventArgs e)
        {
            divMessage.Visible = true;

            // validate captcha:
            if (Request["g-recaptcha-response"] == null)
            {
                divMessage.InnerHtml = "Error, no Captcha field form.  Intente mas tarde o por favor contacte a soporte técnico si el error persiste.";
                return;
            }

            var Recaptchav2 = new RecaptchaVerificationHelper();


            if (string.IsNullOrEmpty(Request["g-recaptcha-response"].ToString()))
            {
                divMessage.InnerHtml = "El Captcha no puede estar vacio.";
                return;
            }
            else
            {
                string secretkey = Global.Configuration.Security.Google.Recaptcha.v2.GetGoogleRecaptchaSecretKey();

                RecaptchaVerificationResult result = Recaptchav2.VerifyRecaptchaResponse(secretkey, Request["g-recaptcha-response"].ToString());

                if (result == RecaptchaVerificationResult.Success)
                {
                    //Response.Redirect( "Welcome.aspx" );
                    //divMessage.InnerHtml = "Captcha OK :D";

                    Response.Redirect("~/Admin/Login.aspx", true);
                    //Server.Transfer("~/Default.aspx", true);
                }
                else if (result == RecaptchaVerificationResult.IncorrectCaptchaSolution)
                {
                    divMessage.InnerHtml = "Valor de Captcha NO Valido.";
                    return;
                }
                else
                {
                    divMessage.InnerHtml = "Existe un problema para validar el captcha, intente mas tarde o por favor contacte a soporte técnico.";
                    return;
                }
            }
        }
示例#24
0
        /// <summary>
        /// This method calls the Google ReCaptcha API..
        /// </summary>
        /// <param name="errorMsgId">The id of the form field where the error message should be displayed.</param>
        private void VerifyCaptcha(string errorMsgId)
        {
            const string CaptchaError = "The ReCaptcha checkbox is required.";
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (string.IsNullOrEmpty(recaptchaHelper.Response))
            {
                this.ModelState.AddModelError(errorMsgId, CaptchaError);
                return;
            }

            RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                this.ModelState.AddModelError(errorMsgId, CaptchaError);
            }
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // reCaptcha
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Captcha answer cannot be empty.");
                return(View(model));
            }

            RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError("", "Incorrect captcha answer.");
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
        public ActionResult Contact(Contact contact)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Captcha answer cannot be empty.");
                return(View(contact));
            }

            RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError("", "Incorrect captcha answer.");
            }

            return(View(contact));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            // reCaptcha
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Captcha answer cannot be empty.");
                return(View(model));
            }

            RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError("", "Incorrect captcha answer.");
            }

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, PhoneNumber = model.PhoneNumber
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#28
0
        public ActionResult Create(CreateCommentModel commentModel)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(GlobalConstants.RecaptchaSecretKey);

            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                this.ModelState.AddModelError("Captcha", "Invalid captcha");
            }

            if (commentModel != null && this.ModelState.IsValid)
            {
                var created = this.CommentService.Create(commentModel);
                if (created)
                {
                    return(this.CommentsForArticle(commentModel.ArticleId));
                }
            }

            throw new HttpException(404, "Comment could not be created!");
        }
示例#29
0
        public async Task <ActionResult> Register(RegisterViewModel vm)
        {
            #region Recaptcha
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();
            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Captcha answer cannot be empty.");
                return(View(vm));
            }
            RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError("", "Incorrect captcha answer.");
            }
            #endregion

            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            if (this._userSertvice.EmailExist(vm.EmailAddress))
            {
                ModelState.AddModelError("EmailAddress", "Email already in use.");
                return(View(vm));
            }

            var user = new User()
            {
                Firstname         = vm.Firstname,
                Lastname          = vm.Lastname,
                EmailAddress      = vm.EmailAddress,
                ClearTextPassword = vm.Password
            };

            this._userSertvice.Add(user);

            return(RedirectToAction("Login")
                   .Success("Account successfully created."));
        }
示例#30
0
        private bool ValidateRecaptcha()
        {
            bool recaptchaSuccess = true;

            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Captcha answer cannot be empty.");
                recaptchaSuccess = false;
            }

            RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError("", "Incorrect captcha answer.");
                recaptchaSuccess = false;
            }
            return(recaptchaSuccess);
        }
        public async Task <ActionResult> Create(Business business)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            //Check if Captcha is empty
            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("", "Captcha answer cannot be empty.");
                return(View(business));
            }

            RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();

            //Check if captcha is not a success
            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                //Return user to business page with an error
                ModelState.AddModelError("", "Incorrect captcha answer.");
                return(View(business));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    //Add the current datetime value
                    business.DateTime = System.DateTime.Now;

                    //Add business if model and captcha are valid
                    db.Businesses.Add(business);

                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(business));
                }
            }
        }
示例#32
0
        /// <summary>
        /// Verifies the user's answer to the recaptcha challenge.
        /// </summary>
        /// <returns>Returns the verification result as <see cref="RecaptchaVerificationResult"/> enum value.</returns>
        ///<exception cref="InvalidOperationException">The private key is null or empty.</exception>
        ///<exception cref="System.Net.WebException">The time-out period for the recaptcha verification request expired.</exception>
        public Task<RecaptchaVerificationResult> VerifyTaskAsync()
        {
            if (_VerificationHelper == null)
            {
                _VerificationHelper = new RecaptchaVerificationHelper(this.PrivateKey);
            }

            return _VerificationHelper.VerifyRecaptchaResponseTaskAsync();
        }
示例#33
0
        /// <summary>
        /// Verifies the user's answer to the recaptcha challenge.
        /// </summary>
        /// <returns>Returns the verification result as <see cref="RecaptchaVerificationResult"/> enum value.</returns>
        ///<exception cref="InvalidOperationException">The private key is null or empty.</exception>
        ///<exception cref="System.Net.WebException">The time-out period for the recaptcha verification request expired.</exception>
        public RecaptchaVerificationResult Verify()
        {
            if (_VerificationHelper == null)
            {
                _VerificationHelper = new RecaptchaVerificationHelper(this.PrivateKey);
            }

            return _VerificationHelper.VerifyRecaptchaResponse();
        }
示例#34
0
        /// <summary>
        /// Calls the OnLoad method of the parent class <see cref="System.Web.UI.WebControls.WebControl"/> and initializes the internal state of the <see cref="Recaptcha"/> control for verification of the user's response to the recaptcha challenge.
        /// </summary>
        /// <param name="e">The <see cref="EventArgs"/> object passed to the Load event of the control.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (this.Page.IsPostBack)
            {
                _VerificationHelper = new RecaptchaVerificationHelper(this.PrivateKey);
            }
        }