Ejemplo n.º 1
0
        public void VerifyCodeImage()
        {
            var vCode = new ValidationCode();

            try
            {
                vCode.FontSize = 15;
#if DEBUG
                vCode.Code = "1234";
#endif
                var image = vCode.NextImage(4, HatchStyle.DarkVertical, false);
                Session[login_verify_code_image] = vCode.Code;

                using (var ms = new MemoryStream())
                {
                    image.Save(ms, ImageFormat.Gif);
                    Response.ClearContent();
                    Response.ContentType = "image/Gif";
                    Response.BinaryWrite(ms.ToArray());
                    image.Dispose();
                    Response.End();
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
 public ErrorResult(HttpStatusCode statusCode, string message, HttpRequestMessage httpRequest, ValidationCode errorCode = ValidationCode.Unknown)
 {
     Request    = httpRequest;
     StatusCode = statusCode;
     Message    = message;
     ErrorCode  = errorCode;
 }
Ejemplo n.º 3
0
        public JsonResult VerifyValidationCode(string telNo, string code)
        {
            string result = null;

            using (var db = new DBHelp().Instance)
            {
                var validation = new ValidationCode
                {
                    TelePhoneNum = telNo,
                    Code         = code,
                    CreateDT     = DateTime.Now,
                    Description  = "验证码",
                    Status       = 0,
                    EscapeTime   = 60
                };

                var temp = db.Queryable <ValidationCode>().Where(x => x.TelePhoneNum == telNo && x.Status == 0 && x.Code == code);

                if (temp.Any())
                {
                    result = "SUCCESS";
                    temp.Context.Deleteable <ValidationCode>().ExecuteCommand();
                }
                else
                {
                    result = "FALSE";
                }
            }

            return(new JsonResult(new { msg = result }));
        }
Ejemplo n.º 4
0
 public VulcanValidationItem(IFrameworkItem invalidAstNode, string propertyName, Severity severity, ValidationCode validationCode, string message, string recommendation)
 {
     InvalidItem = invalidAstNode;
     PropertyName = propertyName;
     Severity = severity;
     ValidationCode = validationCode;
     Message = message;
     Recommendation = recommendation;
 }
Ejemplo n.º 5
0
 public VulcanValidationItem(IFrameworkItem invalidAstNode, string propertyName, Severity severity, ValidationCode validationCode, string message, string recommendation)
 {
     InvalidItem    = invalidAstNode;
     PropertyName   = propertyName;
     Severity       = severity;
     ValidationCode = validationCode;
     Message        = message;
     Recommendation = recommendation;
 }
Ejemplo n.º 6
0
        public ActionResult VerificationCode()
        {
            var code = new ValidationCode();
            var text = code.GetRandomString(4);

            TempData["VerificationCode"] = text;
            var image = code.CreateImage(text);

            return(File(image, "image/bmp"));
        }
Ejemplo n.º 7
0
        public void GetBeerXML_Invalid_Exception()
        {
            Mock <BeerXMLEntityBase> entity = new Mock <BeerXMLEntityBase>();

            entity.Setup(e => e.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(false);

            using (MemoryStream ms = new MemoryStream())
            {
                ValidationCode errorCode = entity.Object.GetBeerXML(ms);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Outputs the BeerXML representing this instance to the given file
        /// </summary>
        /// <returns></returns>
        /// <exception cref="BeerXMLInvalidObjectException"></exception>
        public ValidationCode GetBeerXML(string filePath)
        {
            ValidationCode code = ValidationCode.SUCCESS;

            if (this.IsValid(ref code) || this.AllowInvalidSerialization)
            {
                this.Serializer.Serialize(this, filePath);
                return(code);
            }

            throw new BeerXMLInvalidObjectException(code, string.Format("Validation failed for [{0}] with code [{1}]", this.ToString(), code.ToString()));
        }
Ejemplo n.º 9
0
        public virtual ActionResult <byte[]> NewValidationCode([FromQuery][Required()] string accessToken)
        {
            if (!ValidateUser(accessToken))
            {
                return(StatusCode(403));
            }
            var result = new ValidationCode();

            _context.ValidationCodes.Add(result);
            _context.SaveChanges();
            return(StatusCode(200, result.Code));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns a bool indicating if this instance's conditional properties will produce valid BeerXML.
        /// </summary>
        /// <param name="errorCode">Reason for validation failure, if applicable</param>
        /// <returns></returns>
        protected override bool ValidateConditionalProperties(ref ValidationCode errorCode)
        {
            bool result = true;

            if (this.Type == MashStepType.Decoction &&
                this.Infuse_Amount != null)
            {
                result     = false;
                errorCode |= ValidationCode.DECOCTION_NON_EMPTY_INFUSE_AMOUNT;
            }

            return(result);
        }
Ejemplo n.º 11
0
        public void MashStep_Valid_ErrorCode()
        {
            Mash_Step steps = new Mash_Step(
                MashStepType.Infusion,
                1.0,
                1.0,
                "Step 1");

            ValidationCode errorCode = ValidationCode.SUCCESS;

            steps.IsValid(ref errorCode);

            Assert.AreEqual(ValidationCode.SUCCESS, errorCode);
        }
Ejemplo n.º 12
0
        public void Yeast_Valid_ErrorCode()
        {
            Yeast yeast = new Yeast(
                YeastType.Ale,
                YeastForm.Culture,
                3,
                "Test");

            ValidationCode errorCode = ValidationCode.SUCCESS;

            yeast.IsValid(ref errorCode);

            Assert.AreEqual(ValidationCode.SUCCESS, errorCode);
        }
Ejemplo n.º 13
0
        // GET: Util


        #region 接口

        /// <summary>
        /// 生成验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult VerifyCode()
        {
            ValidationCode vCode        = new ValidationCode();
            var            validateCode = new NIU.Core.VerifyCode {
                Length = 4, FontSize = 16, EnableChaos = true, EnableTwistImage = true
            };
            var code = validateCode.CreateVerifyCode();

            Session[vCode.SessionName] = code.ToUpper();
            Session.Timeout            = 5;
            var bytes = validateCode.CreateValidateGraphic(code);

            return(File(bytes, @"image/jpeg"));
        }
Ejemplo n.º 14
0
        public void Equipments_Valid_NonEmpty()
        {
            Equipments equipments = new Equipments();

            Mock <Equipment> equipment = GetMockEquipment();

            equipment.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            equipments.Add(equipment.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // need to suppress the type check because moq uses a different type
            Assert.IsTrue(equipments.IsValidRecordSet(ref errorCode, suppressTypeCheck: true));
        }
Ejemplo n.º 15
0
        public void Misc_Valid_ErrorCode()
        {
            Misc misc = new Misc(
                MiscType.Fining,
                MiscUse.Boil,
                1.0,
                1.0,
                "Test");

            ValidationCode errorCode = ValidationCode.SUCCESS;

            misc.IsValid();

            Assert.AreEqual(ValidationCode.SUCCESS, errorCode);
        }
Ejemplo n.º 16
0
        public void Yeasts_Valid_NonEmpty()
        {
            Yeasts yeasts = new Yeasts();

            Mock <Yeast> yeast = GetMockYeast();

            yeast.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            yeasts.Add(yeast.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // need to suppress the type check because moq uses a different type
            Assert.IsTrue(yeasts.IsValidRecordSet(ref errorCode, suppressTypeCheck: true));
        }
Ejemplo n.º 17
0
        public void Waters_Valid_NonEmpty()
        {
            Waters waters = new Waters();

            Mock <Water> water = GetMockWater();

            water.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            waters.Add(water.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // need to suppress the type check because moq uses a different type
            Assert.IsTrue(waters.IsValidRecordSet(ref errorCode, suppressTypeCheck: true));
        }
Ejemplo n.º 18
0
        public void Hop_Valid_ErrorCode()
        {
            Hop hop = new Hop(
                "Citra",
                1.2,
                1.2,
                HopUse.Aroma,
                2);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            hop.IsValid(ref errorCode);

            Assert.AreEqual(ValidationCode.SUCCESS, errorCode);
        }
Ejemplo n.º 19
0
        public void Mash_EmptySteps_Valid_ErrorCode()
        {
            Mash_Steps steps = new Mash_Steps();

            Mash mash = new Mash(
                70,
                steps,
                "Empty");

            ValidationCode errorCode = ValidationCode.SUCCESS;

            mash.IsValid(ref errorCode);

            Assert.AreEqual(ValidationCode.SUCCESS, errorCode);
        }
Ejemplo n.º 20
0
        public void Mashs_Valid_NonEmpty()
        {
            Mashs mashs = new Mashs();

            Mock <Mash> mash = GetMockMash();

            mash.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            mashs.Add(mash.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // need to suppress the type check because moq uses a different type
            Assert.IsTrue(mashs.IsValidRecordSet(ref errorCode, suppressTypeCheck: true));
        }
Ejemplo n.º 21
0
        public void Fermentables_Valid_NonEmpty()
        {
            Fermentables fermentables = new Fermentables();

            Mock <Fermentable> fermentable = GetMockFermentable();

            fermentable.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            fermentables.Add(fermentable.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // need to suppress the type check because moq uses a different type
            Assert.IsTrue(fermentables.IsValidRecordSet(ref errorCode, suppressTypeCheck: true));
        }
Ejemplo n.º 22
0
        public void Hops_Valid_NonEmpty()
        {
            Hops hops = new Hops();

            Mock <Hop> hop = GetMockHop();

            hop.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            hops.Add(hop.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // need to suppress the type check because moq uses a different type
            Assert.IsTrue(hops.IsValidRecordSet(ref errorCode, suppressTypeCheck: true));
        }
Ejemplo n.º 23
0
        public bool GetValidationCode(string telNo)
        {
            //检查手机号 如果已经使用过,就不给验证码
            //如果存在未使用的号码,看是否在有效时间内,如果在就不给验证码,不在就删除这条记录,重新生成验证码

            using (var db = new DBHelp().Instance)
            {
                var bookinfo    = db.Queryable <ReservationInfo>().Where(x => x.Telephone == telNo);
                var codeExpired = db.Queryable <ValidationCode>().Where(x => x.TelePhoneNum == telNo && x.CreateDT.AddSeconds(x.EscapeTime) > DateTime.Now);
                if (bookinfo.Any() || codeExpired.Any())
                {
                    return(false);
                }
                else
                {
                    string code;
                    try
                    {
                        //生成code
                        var sendResponse = Util.SendMsg.GetSms(telNo, out code);
                        if (!string.IsNullOrEmpty(code))
                        {
                            var validation = new ValidationCode
                            {
                                TelePhoneNum = telNo,
                                Code         = code,
                                CreateDT     = DateTime.Now,
                                Description  = "验证码",
                                Status       = 0,
                                EscapeTime   = 60
                            };

                            db.Deleteable <ValidationCode>().Where(x => x.TelePhoneNum == telNo).ExecuteCommand();
                            db.Saveable(validation).ExecuteCommand();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
            }
        }
Ejemplo n.º 24
0
        public void Equipments_Invalid_BadType()
        {
            Equipments equipments = new Equipments();

            Mock <Equipment> equipment = GetMockEquipment();

            equipment.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            equipments.Add(equipment.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // do not suppress type check. Since moq uses a different type anyway,
            // there is no need to test with a different IRecord type
            Assert.IsFalse(equipments.IsValidRecordSet(ref errorCode, suppressTypeCheck: false));
        }
Ejemplo n.º 25
0
        public void MashStep_Decotion_NonNullInfusion_Invalid_ErrorCode()
        {
            Mash_Step steps = new Mash_Step(
                MashStepType.Decoction,
                1.0,
                1.0,
                "Step 1");

            steps.Infuse_Amount = 1.0;

            ValidationCode errorCode = ValidationCode.SUCCESS;

            steps.IsValid(ref errorCode);

            Assert.AreEqual(ValidationCode.DECOCTION_NON_EMPTY_INFUSE_AMOUNT, errorCode);
        }
Ejemplo n.º 26
0
        public void Hops_Invalid_BadType()
        {
            Hops hops = new Hops();

            Mock <Hop> hop = GetMockHop();

            hop.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            hops.Add(hop.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // do not suppress type check. Since moq uses a different type anyway,
            // there is no need to test with a different IRecord type
            Assert.IsFalse(hops.IsValidRecordSet(ref errorCode, suppressTypeCheck: false));
        }
Ejemplo n.º 27
0
        public void Mashs_Invalid_BadType()
        {
            Mashs mashs = new Mashs();

            Mock <Mash> mash = GetMockMash();

            mash.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            mashs.Add(mash.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // do not suppress type check. Since moq uses a different type anyway,
            // there is no need to test with a different IRecord type
            Assert.IsFalse(mashs.IsValidRecordSet(ref errorCode, suppressTypeCheck: false));
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Returns a bool indicating if this instance's conditional properties will produce valid BeerXML.
        /// </summary>
        /// <param name="errorCode">Reason for validation failure, if applicable</param>
        /// <returns></returns>
        protected override bool ValidateConditionalProperties(ref ValidationCode errorCode)
        {
            bool result = true;

            // efficiency is required for partial masah and all grain
            if (this.Type == RecipeType.Partial_Mash || this.Type == RecipeType.All_Grain)
            {
                if (this.Efficiency == null)
                {
                    result     = false;
                    errorCode |= ValidationCode.EFFICIENCY_REQUIRED_FOR_GRAINS;
                }
            }

            return(result);
        }
Ejemplo n.º 29
0
        public void Recipe_Valid_ErrorCode()
        {
            Recipe recipe = GetRecipe(
                RecipeType.Extract,
                "Michael",
                5.0,
                6.5,
                60,
                "Test");

            ValidationCode errorCode = ValidationCode.SUCCESS;

            recipe.IsValid(ref errorCode);

            Assert.AreEqual(ValidationCode.SUCCESS, errorCode);
        }
Ejemplo n.º 30
0
        public void Fermentables_Invalid_BadType()
        {
            Fermentables fermentables = new Fermentables();

            Mock <Fermentable> fermentable = GetMockFermentable();

            fermentable.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            fermentables.Add(fermentable.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // do not suppress type check. Since moq uses a different type anyway,
            // there is no need to test with a different IRecord type
            Assert.IsFalse(fermentables.IsValidRecordSet(ref errorCode, suppressTypeCheck: false));
        }
Ejemplo n.º 31
0
        public void Waters_Invalid_BadType()
        {
            Waters waters = new Waters();

            Mock <Water> water = GetMockWater();

            water.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            waters.Add(water.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // do not suppress type check. Since moq uses a different type anyway,
            // there is no need to test with a different IRecord type
            Assert.IsFalse(waters.IsValidRecordSet(ref errorCode, suppressTypeCheck: false));
        }
Ejemplo n.º 32
0
 private static string GetErrorId(ValidationCode validationCode)
 {
     return ((int)validationCode).ToString();
 }