コード例 #1
0
 public ActionResult Captcha()
 {
     if (ModelState.IsValid)
     {
         ModelState.Clear();
         if (Request.IsAjaxRequest())
         {
             return(Json(new
             {
                 Message = "Success",
                 IsOk = bool.TrueString
             }));
         }
         return(View());
     }
     if (Request.IsAjaxRequest())
     {
         IUpdateInfoModel captchaValue = this.GenerateCaptchaValue(5);
         return(Json(new
         {
             Message = "Captcha is not valid",
             Captcha =
                 new Dictionary <string, string>
             {
                 { captchaValue.ImageElementId, captchaValue.ImageUrl },
                 { captchaValue.TokenElementId, captchaValue.TokenValue }
             }
         }));
     }
     return(View());
 }
コード例 #2
0
        /// <summary>
        ///     Generates a java-script to update the captcha.
        /// </summary>
        /// <param name="updateInfo">
        ///     The specified <see cref="IUpdateInfoModel" />.
        /// </param>
        /// <returns>
        ///     An instance of <see cref="ActionResult" /> to update the captcha.
        /// </returns>
        public virtual ActionResult RefreshCaptcha(IUpdateInfoModel updateInfo)
        {
            Validate.ArgumentNotNull(updateInfo, "updateInfo");
            string script = string.Format(@"$('#{0}').attr(""value"", ""{1}"");
$('#{2}').attr(""src"", ""{3}"");", updateInfo.TokenElementId,
                                          updateInfo.TokenValue,
                                          updateInfo.ImageElementId, updateInfo.ImageUrl);

            return(new JavaScriptResult {
                Script = script
            });
        }
コード例 #3
0
        /// <summary>
        ///     Refreshes a captcha.
        /// </summary>
        /// <returns>
        ///     An instance of <see cref="ActionResult" />.
        /// </returns>
        public virtual ActionResult Refresh()
        {
            var parameterContainer = new RequestParameterContainer(Request);

            if (Request.IsAjaxRequest())
            {
                IUpdateInfoModel updateInfoModel =
                    CaptchaUtils.CaptchaManagerFactory(parameterContainer).Update(parameterContainer);
                return(CaptchaUtils.BuilderProviderFactory(parameterContainer).RefreshCaptcha(updateInfoModel));
            }
            return(Redirect(Request.UrlReferrer.AbsolutePath));
        }
コード例 #4
0
        public async Task <ActionResult> GuestRegister(SearchUser suser)
        {
            if (!CaptchaMvc.HtmlHelpers.CaptchaHelper.IsCaptchaValid(this, "error"))
            {
                IUpdateInfoModel captchaValue = CaptchaMvc.HtmlHelpers.CaptchaHelper.GenerateCaptchaValue(this, 4);

                //ModelState.AddModelError("", "Wrong Captcha!");
                return(Json(new
                {
                    Message = "Captcha is not valid",
                    Captcha =
                        new Dictionary <string, string>
                    {
                        { captchaValue.ImageElementId, captchaValue.ImageUrl },
                        { captchaValue.TokenElementId, captchaValue.TokenValue }
                    }
                }));
            }

            if (ModelState.IsValid)
            {
                //string cpt = Session["GuestCaptcha"] as string;
            }
            var evtuser = new EventGuestUser();

            evtuser.Email       = suser.Email;
            evtuser.EventId     = suser.EventId;
            evtuser.PhoneNumber = suser.PhoneNumber;
            evtuser.Name        = suser.Name;
            db.EventGuestUsers.Add(evtuser);
            TempData["GuestSuccess"] = "Thanks for signing up. See you at the event.";
            await db.SaveChangesAsync();

            var evtdetail = db.Events.FirstOrDefault(x => x.Id == suser.EventId);

            await SendEventReminderAsync(true, evtdetail, suser.Email);

            return(Json(new
            {
                Message = "OK"
            }));
        }