PageRenderTime 16ms CodeModel.GetById 8ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

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

#
C# | 123 lines | 37 code | 16 blank | 70 comment | 5 complexity | f1af7281d70298608905d1f1c8850f1c MD5 | raw file
  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
 18// Adapted for dotnetblogengine by Filip Stanek ( http://www.bloodforge.com )
 19
 20namespace Recaptcha
 21{
 22    /// <summary>
 23    /// The recaptcha response.
 24    /// </summary>
 25    public class RecaptchaResponse
 26    {
 27        #region Constructors and Destructors
 28
 29        /// <summary>
 30        /// Initializes static members of the <see cref="RecaptchaResponse"/> class. 
 31        /// </summary>
 32        static RecaptchaResponse()
 33        {
 34            Valid = new RecaptchaResponse(true, string.Empty);
 35            RecaptchaNotReachable = new RecaptchaResponse(false, "recaptcha-not-reachable");
 36            InvalidSolution = new RecaptchaResponse(false, "incorrect-captcha-sol");
 37        }
 38
 39        /// <summary>
 40        /// Initializes a new instance of the <see cref="RecaptchaResponse"/> class.
 41        /// </summary>
 42        /// <param name="valid">
 43        /// if set to <c>true</c> [is valid].
 44        /// </param>
 45        /// <param name="errorCode">
 46        /// The error code.
 47        /// </param>
 48        internal RecaptchaResponse(bool valid, string errorCode)
 49        {
 50            this.IsValid = valid;
 51            this.ErrorCode = errorCode;
 52        }
 53
 54        #endregion
 55
 56        #region Properties
 57
 58        /// <summary>
 59        ///     Gets or sets the invalid solution.
 60        /// </summary>
 61        /// <value>The invalid solution.</value>
 62        public static RecaptchaResponse InvalidSolution { get; set; }
 63
 64        /// <summary>
 65        ///     Gets or sets the recaptcha not reachable.
 66        /// </summary>
 67        /// <value>The recaptcha not reachable.</value>
 68        public static RecaptchaResponse RecaptchaNotReachable { get; set; }
 69
 70        /// <summary>
 71        ///     Gets or sets whether valid.
 72        /// </summary>
 73        /// <value>Whether valid.</value>
 74        public static RecaptchaResponse Valid { get; set; }
 75
 76        /// <summary>
 77        ///     Gets the error code.
 78        /// </summary>
 79        /// <value>The error code.</value>
 80        public string ErrorCode { get; private set; }
 81
 82        /// <summary>
 83        ///     Gets a value indicating whether this instance is valid.
 84        /// </summary>
 85        /// <value><c>true</c> if this instance is valid; otherwise, <c>false</c>.</value>
 86        public bool IsValid { get; private set; }
 87
 88        #endregion
 89
 90        #region Public Methods
 91
 92        /// <summary>
 93        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
 94        /// </summary>
 95        /// <param name="obj">
 96        /// The <see cref="System.Object"/> to compare with this instance.
 97        /// </param>
 98        /// <returns>
 99        /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
100        /// </returns>
101        /// <exception cref="T:System.NullReferenceException">
102        /// The <paramref name="obj"/> parameter is null.
103        /// </exception>
104        public override bool Equals(object obj)
105        {
106            var other = (RecaptchaResponse)obj;
107            return other != null && (other.IsValid == this.IsValid && other.ErrorCode == this.ErrorCode);
108        }
109
110        /// <summary>
111        /// Returns a hash code for this instance.
112        /// </summary>
113        /// <returns>
114        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
115        /// </returns>
116        public override int GetHashCode()
117        {
118            return this.IsValid.GetHashCode() ^ this.ErrorCode.GetHashCode();
119        }
120
121        #endregion
122    }
123}