/// <summary> /// Html Helper to build and render the Captcha control /// </summary> /// <param name="helper">HtmlHelper class provides a set of helper methods whose purpose is to help you create HTML controls programmatically</param> /// <returns></returns> public static string GenerateCaptcha(this HtmlHelper helper) { var captchaControl = new RecaptchaControl { ID = "recaptcha", Theme = "red", //http://wiki.recaptcha.net/index.php/Theme PublicKey = ConfigurationManager.AppSettings["ReCaptchaPublicKey"], PrivateKey = ConfigurationManager.AppSettings["ReCaptchaPrivateKey"] }; var htmlWriter = new HtmlTextWriter(new StringWriter()); captchaControl.RenderControl(htmlWriter); return htmlWriter.InnerWriter.ToString(); }
public static string GenerateReCaptcha(this HtmlHelper helper, string id, string theme) { if (string.IsNullOrEmpty(Settings.ReCaptchaPublicKey) || string.IsNullOrEmpty(Settings.ReCaptchaPrivateKey)) throw new ApplicationException("reCAPTCHA needs to be configured with a public & private key."); RecaptchaControl recaptchaControl1 = new RecaptchaControl(); recaptchaControl1.ID = id; recaptchaControl1.Theme = theme; recaptchaControl1.PublicKey = Settings.ReCaptchaPublicKey; recaptchaControl1.PrivateKey = Settings.ReCaptchaPrivateKey; RecaptchaControl recaptchaControl2 = recaptchaControl1; HtmlTextWriter writer = new HtmlTextWriter(new StringWriter()); recaptchaControl2.RenderControl(writer); return writer.InnerWriter.ToString(); }
public static MvcHtmlString GenerateCaptcha(this HtmlHelper helper) { var control = new RecaptchaControl { ID = "recaptcha", Theme = "clean", PublicKey = ConfigurationManager.AppSettings["ReCaptchaPublicKey"], PrivateKey = ConfigurationManager.AppSettings["ReCaptchaPrivateKey"] }; var writer = new HtmlTextWriter(new StringWriter()); control.RenderControl(writer); var html = writer.InnerWriter.ToString(); return MvcHtmlString.Create(html); }
/// <summary> /// Html Helper to build and render the Captcha control /// </summary> /// <param name="helper">HtmlHelper class provides a set of helper methods whose purpose is to help you create HTML controls programmatically</param> /// <returns></returns> public static IHtmlString GenerateCaptcha(this HtmlHelper helper, string theme = "clean") { var captchaControl = new RecaptchaControl { ID = "recaptcha", Theme = theme, PublicKey = ConfigurationManager.AppSettings["ReCaptchaPublicKey"], PrivateKey = ConfigurationManager.AppSettings["ReCaptchaPrivateKey"] }; var htmlWriter = new HtmlTextWriter(new StringWriter()); captchaControl.RenderControl(htmlWriter); return new HtmlString(htmlWriter.InnerWriter.ToString()); }
public static MvcHtmlString Generate(this HtmlHelper helper) { var captchaControl = new Recaptcha.RecaptchaControl { ID = "recaptcha", Theme = "clean", PublicKey = CaptchaValidatorAttribute.PUBLIC_KEY, PrivateKey = CaptchaValidatorAttribute.PRIVATE_KEY }; var htmlWriter = new HtmlTextWriter(new StringWriter()); captchaControl.RenderControl(htmlWriter); return new MvcHtmlString(htmlWriter.InnerWriter.ToString()); }
public static string GenerateCaptcha(this HtmlHelper helper) { // Registered under [email protected] RecaptchaControl captchaControl = new RecaptchaControl { ID = "recaptcha", Theme = "white", PublicKey = "6Lfvw8ISAAAAADr79kKTnEopgt7-HUzAcR2vzSsb", PrivateKey = "6Lfvw8ISAAAAAPj5Xlu-DZ7EPF21bvzB3z65STHr" }; HtmlTextWriter htmlWriter = new HtmlTextWriter(new StringWriter()); captchaControl.RenderControl(htmlWriter); return htmlWriter.InnerWriter.ToString(); }
protected override void CreateChildControls() { base.CreateChildControls(); //lbl = new Label(); //lbl.Visible = false; //lbl.ID = "lblResult"; //this.Controls.Add(lbl); captcha = new RecaptchaControl(); captcha.Theme="red"; captcha.PublicKey = "6LcDZM8SAAAAACRZLSGSISnDMMVTsE7oQmSOstXM"; captcha.PrivateKey = "6LcDZM8SAAAAAHiWOJFvcLai5dWndgKHarZHhBkT"; this.Controls.Add(captcha); }
public static MvcHtmlString Generate(this HtmlHelper helper) { var captchaControl = new Recaptcha.RecaptchaControl { ID = "recaptcha", Theme = "clean", PublicKey = CaptchaValidatorAttribute.PUBLIC_KEY, PrivateKey = CaptchaValidatorAttribute.PRIVATE_KEY }; var htmlWriter = new HtmlTextWriter(new StringWriter()); captchaControl.RenderControl(htmlWriter); return(new MvcHtmlString(htmlWriter.InnerWriter.ToString())); }
/// <summary> /// Generates CAPTCHA HTML using reCAPTCHA. /// </summary> /// <param name="htmlHelper">The view's HTML helper.</param> /// <param name="fallbackMessage">An optional message to display above the CAPTCHA when it is displayed as a fallback.</param> /// <returns>The reCAPTCHA HTML.</returns> public IHtmlString Generate( HtmlHelper htmlHelper, string fallbackMessage = null) { if (htmlHelper == null) { throw new ArgumentNullException("htmlHelper"); } IConfigurationSource configurationSource = GetConfigurationSource(); var publicApiKey = configurationSource.GetConfigurationValue(Const.ReCaptchaPublicKeyAppSettingKey); if (publicApiKey == null) { if (!htmlHelper.ViewContext.HttpContext.Request.IsLocal) throw new InvalidOperationException(ErrorMessage.DefaultReCaptchApiKeysOnlyAllowedForLocalRequest); publicApiKey = Const.ReCaptchaLocalhostPublicKey; } var privateApiKey = configurationSource.GetConfigurationValue(Const.ReCaptchaPrivateKeyAppSettingKey); if (privateApiKey == null) { if (!htmlHelper.ViewContext.HttpContext.Request.IsLocal) throw new InvalidOperationException(ErrorMessage.DefaultReCaptchApiKeysOnlyAllowedForLocalRequest); privateApiKey = Const.ReCaptchaLocalhostPrivateKey; } var recaptchaControl = new RecaptchaControl { ID = Const.ReCaptchControlId, PublicKey = publicApiKey, PrivateKey = privateApiKey, }; var htmlWriter = new HtmlTextWriter(new StringWriter()); recaptchaControl.RenderControl(htmlWriter); var captchaHtml = htmlWriter.InnerWriter.ToString(); const string template = @"<div class=""PoliteCaptcha editor-field""><span class=""field-validation-error"" data-valmsg-for=""PoliteCaptcha""><span htmlfor=""PoliteCaptcha"">{0}</span></span>{1}</div>"; return new MvcHtmlString(string.Format(template, fallbackMessage ?? Const.DefaulFallbackMessage, captchaHtml)); }
public static MvcHtmlString GenerateCaptcha(this HtmlHelper helper) { var captchaSettings = EngineContext.Current.Resolve<CaptchaSettings>(); // cho phép cấu hình theme cho recaptcha google từ settings, cấu hình này có thể là xanh đỏ tím vàng gì gì đó string theme = string.IsNullOrEmpty(captchaSettings.ReCaptchaTheme) ? "white" : captchaSettings.ReCaptchaTheme; var recaptchaControl = new RecaptchaControl { ID = "recaptcha", Theme = theme, PublicKey = captchaSettings.ReCaptchaPublicKey, PrivateKey = captchaSettings.ReCaptchaPrivateKey }; var htmlWriter = new HtmlTextWriter(new StringWriter()); recaptchaControl.RenderControl(htmlWriter); return new MvcHtmlString(htmlWriter.InnerWriter.ToString()); }
/// <summary> /// Html Helper to build and render the Captcha control /// </summary> /// <param name="helper">HtmlHelper class provides a set of helper methods whose purpose is to help you create HTML controls programmatically</param> /// <returns></returns> public static string GenerateCaptcha(this HtmlHelper helper) { if (IsDisabled()) return string.Empty; var captchaControl = new RecaptchaControl { ID = "recaptcha", Theme = "clean", //http://wiki.recaptcha.net/index.php/Theme PublicKey = ReCaptchaPublicKey, PrivateKey = ReCaptchaPrivateKey }; if (string.IsNullOrEmpty(ReCaptchaPublicKey) || string.IsNullOrEmpty(ReCaptchaPrivateKey)) return string.Empty; var htmlWriter = new HtmlTextWriter(new StringWriter()); captchaControl.RenderControl(htmlWriter); return htmlWriter.InnerWriter.ToString(); }
/// <summary> /// Renders the Recaptcha control as HTML, if recaptcha is enabled. /// </summary> public static MvcHtmlString RenderCaptcha(this HtmlHelper helper) { if (RoadkillSettings.IsRecaptchaEnabled) { RecaptchaControl control = new RecaptchaControl(); control.ID = "recaptcha"; control.Theme = "clean"; control.PublicKey = RoadkillSettings.RecaptchaPublicKey; control.PrivateKey = RoadkillSettings.RecaptchaPrivateKey; using (StringWriter stringWriter = new StringWriter()) { using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter)) { stringWriter.WriteLine("<br/><label class=\"userlabel\">As an anti-spam measure, please enter the two words below</label><br style=\"clear:both\"><br/>"); control.RenderControl(htmlWriter); stringWriter.WriteLine("<br/>"); return MvcHtmlString.Create(htmlWriter.InnerWriter.ToString()); } } } else { return MvcHtmlString.Empty; } }