/// <summary> /// Makes the captcha "intelligent". /// </summary> /// <param name="captcha"> /// The specified <see cref="ICaptcha" />. /// </param> /// <param name="parameters">The specified parameters, if any.</param> /// <returns> /// An instance of <see cref="ICaptcha" />. /// </returns> public static ICaptcha AsIntelligent(this ICaptcha captcha, params ParameterModel[] parameters) { List <ParameterModel> list = CaptchaUtils.GetParameters(parameters); var container = new CombinedParameterContainer(new ParameterModelContainer(list), captcha.BuildInfo.ParameterContainer); var captchaManager = CaptchaUtils.CaptchaManagerFactory(container); if (captchaManager.IntelligencePolicy == null) { throw new NullReferenceException("The IntelligencePolicy property is null."); } return(captchaManager.IntelligencePolicy.MakeIntelligent(captchaManager, captcha, container)); }
/// <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="ICaptchaManager"/> using the specified <see cref="ControllerBase"/>. /// </summary> /// <param name="controllerBase">The specified <see cref="ControllerBase"/>.</param> /// <returns>An instance of <see cref="ICaptchaManager"/>.</returns> public static ICaptchaManager GetCaptchaManager(this ControllerBase controllerBase) { return(CaptchaUtils.CaptchaManagerFactory( new RequestParameterContainer(controllerBase.ControllerContext.HttpContext.Request))); }