Skip to content

Commit

Permalink
added XML doc in preparation for generating a NuGet package
Browse files Browse the repository at this point in the history
  • Loading branch information
half-ogre committed Feb 7, 2012
1 parent ef2e523 commit e2f02a8
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 5 deletions.
9 changes: 6 additions & 3 deletions PoliteCaptcha/BypassCaptchaGenerator.cs
Expand Up @@ -4,16 +4,19 @@


namespace PoliteCaptcha namespace PoliteCaptcha
{ {
/// <summary>
/// A "fake" CAPTCHA generator that effectively bypasses CAPTCHA generation.
/// </summary>
public class BypassCaptchaGenerator : ICaptchaGenerator public class BypassCaptchaGenerator : ICaptchaGenerator
{ {
/// <summary> /// <summary>
/// This is a "fake" CAPTCHA generator that returns nothing, effectively bypassing CAPTCHA generation. /// Generates "fake" CAPTCHA HTML (returns an empty string), effectively bypassing CAPTCHA generation.
/// </summary> /// </summary>
/// <param name="httpHelper">The view's HTML helper.</param> /// <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> /// <param name="fallbackMessage">An optional message to display above the CAPTCHA when it is displayed as a fallback.</param>
/// <returns>The CAPTCHA's HTML.</returns> /// <returns>The CAPTCHA's HTML.</returns>
public IHtmlString Generate( public IHtmlString Generate(
HtmlHelper httpHelper, HtmlHelper htmlHelper,
string fallbackMessage = null) string fallbackMessage = null)
{ {
return new MvcHtmlString(string.Empty); return new MvcHtmlString(string.Empty);
Expand Down
5 changes: 4 additions & 1 deletion PoliteCaptcha/BypassCaptchaValidator.cs
Expand Up @@ -3,10 +3,13 @@


namespace PoliteCaptcha namespace PoliteCaptcha
{ {
/// <summary>
/// A "fake" CAPTCHA validator that effectively bypasses CAPTCHA validation.
/// </summary>
public class BypassCaptchaValidator : ICaptchaValidator public class BypassCaptchaValidator : ICaptchaValidator
{ {
/// <summary> /// <summary>
/// This is a "fake" CAPTCHA validator that always returns true, effectively bypassing CAPTCHA validation. /// "Fakes" CAPTCHA validation (always returns true), effectively bypassing CAPTCHA validation.
/// </summary> /// </summary>
/// <param name="httpContext">The request's HTTP context.</param> /// <param name="httpContext">The request's HTTP context.</param>
/// <returns>The result of validation; always true.</returns> /// <returns>The result of validation; always true.</returns>
Expand Down
3 changes: 3 additions & 0 deletions PoliteCaptcha/Const.cs
Expand Up @@ -2,6 +2,9 @@


namespace PoliteCaptcha namespace PoliteCaptcha
{ {
/// <summary>
/// The constants used by PoliteCaptcha, all in one convenience place.
/// </summary>
public static class Const public static class Const
{ {
public const string DefaulFallbackMessage = "Your request failed spam prevention. You must complete the CAPTCHA form below to proceed."; public const string DefaulFallbackMessage = "Your request failed spam prevention. You must complete the CAPTCHA form below to proceed.";
Expand Down
11 changes: 10 additions & 1 deletion PoliteCaptcha/ICaptchaGenerator.cs
Expand Up @@ -4,10 +4,19 @@


namespace PoliteCaptcha namespace PoliteCaptcha
{ {
/// <summary>
/// Generates CAPTCHA HTML.
/// </summary>
public interface ICaptchaGenerator public interface ICaptchaGenerator
{ {
/// <summary>
/// Generates CAPTCHA HTML.
/// </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 CAPTCHA's HTML.</returns>
IHtmlString Generate( IHtmlString Generate(
HtmlHelper httpHelper, HtmlHelper htmlHelper,
string fallbackMessage = null); string fallbackMessage = null);
} }
} }
8 changes: 8 additions & 0 deletions PoliteCaptcha/ICaptchaValidator.cs
Expand Up @@ -3,8 +3,16 @@


namespace PoliteCaptcha namespace PoliteCaptcha
{ {
/// <summary>
/// Validates a CAPTCHA response.
/// </summary>
public interface ICaptchaValidator public interface ICaptchaValidator
{ {
/// <summary>
/// Validates a CAPTCHA response.
/// </summary>
/// <param name="httpContext">The request's HTTP context.</param>
/// <returns>The result of validation; true or false.</returns>
bool Validate(HttpContextBase httpContext); bool Validate(HttpContextBase httpContext);
} }
} }
9 changes: 9 additions & 0 deletions PoliteCaptcha/ReCaptchaGenerator.cs
Expand Up @@ -8,8 +8,17 @@


namespace PoliteCaptcha namespace PoliteCaptcha
{ {
/// <summary>
/// A CAPTCHA generator that uses reCAPTCHA; the default CAPTCHA generator used by PoliteCaptcha.
/// </summary>
public class ReCaptchaGenerator : ICaptchaGenerator public class ReCaptchaGenerator : ICaptchaGenerator
{ {
/// <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( public IHtmlString Generate(
HtmlHelper htmlHelper, HtmlHelper htmlHelper,
string fallbackMessage = null) string fallbackMessage = null)
Expand Down
11 changes: 11 additions & 0 deletions PoliteCaptcha/ReCaptchaValidator.cs
Expand Up @@ -5,15 +5,26 @@


namespace PoliteCaptcha namespace PoliteCaptcha
{ {
/// <summary>
/// A CAPTCHA validator that uses reCAPTCHA.
/// </summary>
public class ReCaptchaValidator : ICaptchaValidator public class ReCaptchaValidator : ICaptchaValidator
{ {
readonly RecaptchaValidator recaptchaValidator; readonly RecaptchaValidator recaptchaValidator;


/// <summary>
/// Creates a new ReCaptchValidator object.
/// </summary>
public ReCaptchaValidator() public ReCaptchaValidator()
{ {
recaptchaValidator = new RecaptchaValidator(); recaptchaValidator = new RecaptchaValidator();
} }


/// <summary>
/// Validates a CAPTCHA response using reCAPTCHA.
/// </summary>
/// <param name="httpContext">The request's HTTP context.</param>
/// <returns>The result of validation; true or false.</returns>
public bool Validate(HttpContextBase httpContext) public bool Validate(HttpContextBase httpContext)
{ {
if (httpContext == null) if (httpContext == null)
Expand Down
14 changes: 14 additions & 0 deletions PoliteCaptcha/SpamPreventionHtmlHelpers.cs
Expand Up @@ -5,8 +5,17 @@


namespace PoliteCaptcha namespace PoliteCaptcha
{ {
/// <summary>
/// HTML Helpers for PoliteCaptcha' spam prevention.
/// </summary>
public static class SpamPreventionHtmlHelpers public static class SpamPreventionHtmlHelpers
{ {
/// <summary>
/// Generates the form fields' HTML for spam prevention. Use inside of an ASP.NET MVC form.
/// </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 spam prevention form fields' HTML</returns>
public static IHtmlString SpamPreventionFields( public static IHtmlString SpamPreventionFields(
this HtmlHelper htmlHelper, this HtmlHelper htmlHelper,
string fallbackMessage = null) string fallbackMessage = null)
Expand All @@ -24,6 +33,11 @@ public static class SpamPreventionHtmlHelpers
return htmlHelper.Hidden(Const.NoCaptchaChallengeField, Guid.NewGuid().ToString("N")); return htmlHelper.Hidden(Const.NoCaptchaChallengeField, Guid.NewGuid().ToString("N"));
} }


/// <summary>
/// Generates the JavaScript required for spam prevention. Requires jQuery.
/// </summary>
/// <param name="htmlHelper">The view's HTML helper.</param>
/// <returns>The spam prevention JavaScript.</returns>
public static IHtmlString SpamPreventionScript(this HtmlHelper htmlHelper) public static IHtmlString SpamPreventionScript(this HtmlHelper htmlHelper)
{ {
return new MvcHtmlString( return new MvcHtmlString(
Expand Down
13 changes: 13 additions & 0 deletions PoliteCaptcha/ValidateSpamPreventionAttribute.cs
Expand Up @@ -5,9 +5,16 @@


namespace PoliteCaptcha namespace PoliteCaptcha
{ {
/// <summary>
/// Validates spam prevention; apply to ASP.NET MVC action methods.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class ValidateSpamPreventionAttribute : FilterAttribute, IAuthorizationFilter public class ValidateSpamPreventionAttribute : FilterAttribute, IAuthorizationFilter
{ {
/// <summary>
/// Authorizes the current action by validating spam prevention responses.
/// </summary>
/// <param name="filterContext">The filter's authorization context.</param>
public void OnAuthorization(AuthorizationContext filterContext) public void OnAuthorization(AuthorizationContext filterContext)
{ {
if (filterContext == null) if (filterContext == null)
Expand All @@ -31,6 +38,12 @@ public void OnAuthorization(AuthorizationContext filterContext)
captchaValidator); captchaValidator);
} }


/// <summary>
/// Authorizes spam prevention responses. If validation fails, updates model state accordingly.
/// </summary>
/// <param name="httpContext">The request's HTTP context.</param>
/// <param name="modelState">The request's model state.</param>
/// <param name="captchaValidator">The CAPTCHA validator to use to validate a CAPTCHA response, if present.</param>
public void Authorize( public void Authorize(
HttpContextBase httpContext, HttpContextBase httpContext,
ModelStateDictionary modelState, ModelStateDictionary modelState,
Expand Down

0 comments on commit e2f02a8

Please sign in to comment.