PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/App_Code/Extensions/Recaptcha/RecaptchaResponse.cs

#
C# | 123 lines | 37 code | 16 blank | 70 comment | 5 complexity | f1af7281d70298608905d1f1c8850f1c MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. // Copyright (c) 2007 Adrian Godong, Ben Maurer
  2. // Permission is hereby granted, free of charge, to any person obtaining a copy
  3. // of this software and associated documentation files (the "Software"), to deal
  4. // in the Software without restriction, including without limitation the rights
  5. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  6. // copies of the Software, and to permit persons to whom the Software is
  7. // furnished to do so, subject to the following conditions:
  8. // The above copyright notice and this permission notice shall be included in
  9. // all copies or substantial portions of the Software.
  10. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  14. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  15. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  16. // THE SOFTWARE.
  17. // Adapted for dotnetblogengine by Filip Stanek ( http://www.bloodforge.com )
  18. namespace Recaptcha
  19. {
  20. /// <summary>
  21. /// The recaptcha response.
  22. /// </summary>
  23. public class RecaptchaResponse
  24. {
  25. #region Constructors and Destructors
  26. /// <summary>
  27. /// Initializes static members of the <see cref="RecaptchaResponse"/> class.
  28. /// </summary>
  29. static RecaptchaResponse()
  30. {
  31. Valid = new RecaptchaResponse(true, string.Empty);
  32. RecaptchaNotReachable = new RecaptchaResponse(false, "recaptcha-not-reachable");
  33. InvalidSolution = new RecaptchaResponse(false, "incorrect-captcha-sol");
  34. }
  35. /// <summary>
  36. /// Initializes a new instance of the <see cref="RecaptchaResponse"/> class.
  37. /// </summary>
  38. /// <param name="valid">
  39. /// if set to <c>true</c> [is valid].
  40. /// </param>
  41. /// <param name="errorCode">
  42. /// The error code.
  43. /// </param>
  44. internal RecaptchaResponse(bool valid, string errorCode)
  45. {
  46. this.IsValid = valid;
  47. this.ErrorCode = errorCode;
  48. }
  49. #endregion
  50. #region Properties
  51. /// <summary>
  52. /// Gets or sets the invalid solution.
  53. /// </summary>
  54. /// <value>The invalid solution.</value>
  55. public static RecaptchaResponse InvalidSolution { get; set; }
  56. /// <summary>
  57. /// Gets or sets the recaptcha not reachable.
  58. /// </summary>
  59. /// <value>The recaptcha not reachable.</value>
  60. public static RecaptchaResponse RecaptchaNotReachable { get; set; }
  61. /// <summary>
  62. /// Gets or sets whether valid.
  63. /// </summary>
  64. /// <value>Whether valid.</value>
  65. public static RecaptchaResponse Valid { get; set; }
  66. /// <summary>
  67. /// Gets the error code.
  68. /// </summary>
  69. /// <value>The error code.</value>
  70. public string ErrorCode { get; private set; }
  71. /// <summary>
  72. /// Gets a value indicating whether this instance is valid.
  73. /// </summary>
  74. /// <value><c>true</c> if this instance is valid; otherwise, <c>false</c>.</value>
  75. public bool IsValid { get; private set; }
  76. #endregion
  77. #region Public Methods
  78. /// <summary>
  79. /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
  80. /// </summary>
  81. /// <param name="obj">
  82. /// The <see cref="System.Object"/> to compare with this instance.
  83. /// </param>
  84. /// <returns>
  85. /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
  86. /// </returns>
  87. /// <exception cref="T:System.NullReferenceException">
  88. /// The <paramref name="obj"/> parameter is null.
  89. /// </exception>
  90. public override bool Equals(object obj)
  91. {
  92. var other = (RecaptchaResponse)obj;
  93. return other != null && (other.IsValid == this.IsValid && other.ErrorCode == this.ErrorCode);
  94. }
  95. /// <summary>
  96. /// Returns a hash code for this instance.
  97. /// </summary>
  98. /// <returns>
  99. /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
  100. /// </returns>
  101. public override int GetHashCode()
  102. {
  103. return this.IsValid.GetHashCode() ^ this.ErrorCode.GetHashCode();
  104. }
  105. #endregion
  106. }
  107. }