/// <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)); }
/// <summary> /// Generates a new captcha image. /// </summary> public virtual void Generate() { var parameterContainer = new RequestParameterContainer(Request); try { if (Request.UrlReferrer.AbsolutePath == Request.Url.AbsolutePath) { throw new InvalidOperationException(); } IDrawingModel drawingModel = CaptchaUtils.CaptchaManagerFactory(parameterContainer).GetDrawingModel(parameterContainer); CaptchaUtils.BuilderProviderFactory(parameterContainer).WriteCaptchaImage(Response, drawingModel); } catch (Exception) { CaptchaUtils.BuilderProviderFactory(parameterContainer).WriteErrorImage(Response); } }
/// <summary> /// Gets the <see cref="ICaptchaBuilderProvider"/> using the specified <see cref="ControllerBase"/>. /// </summary> /// <param name="controllerBase">The specified <see cref="ControllerBase"/>.</param> /// <returns>An instance of <see cref="ICaptchaBuilderProvider"/>.</returns> public static ICaptchaBuilderProvider GetCaptchaBuilderProvider(this ControllerBase controllerBase) { return(CaptchaUtils.BuilderProviderFactory( new RequestParameterContainer(controllerBase.ControllerContext.HttpContext.Request))); }