예제 #1
0
        public static void SetModel <T>(CustomVerifier verifier, SystemPlatform plateForm, string uniqueKey, T model) where T : IVerified
        {
            string modelKey = verifier.GetVerifyModelKey(plateForm, uniqueKey);

            model.ExpireTime = DateTime.UtcNow.AddMinutes(Constant.VERIFICATION_CACHE_TIME).ToUnixTime();
            RedisHelper.Set(RedisDBIndex, modelKey, model, TimeSpan.FromMinutes(Constant.TEMPTOKEN_EXPIRED_TIME));
        }
예제 #2
0
        public static void Verify <T>(CustomVerifier verifier, SystemPlatform plateForm, string uniqueKey, Func <T, bool> VerifyFunction) where T : IVerified
        {
            var    errorCountKey = verifier.GetErrorCountKey(plateForm, uniqueKey);
            int    errorCount    = CheckErrorCount(verifier, errorCountKey);
            string modelKey      = verifier.GetVerifyModelKey(plateForm, uniqueKey);

            var model = RedisHelper.Get <T>(RedisDBIndex, modelKey);

            if (model != null && model.ExpireTime <= DateTime.UtcNow.ToUnixTime())
            {
                verifier.CodeExpried();
            }

            bool result = true;

            try
            {
                result = VerifyFunction.Invoke(model);
            }
            catch (Framework.Exceptions.CommonException ce)
            {
                result = false;
                IncreaseErrorCount(verifier, errorCountKey, ce);
            }
            catch (Exception ex)
            {
                result = false;
                IncreaseErrorCount(verifier, errorCountKey);
            }

            if (result)
            {
                if (errorCount > 0)
                {
                    DeleteErrorCount(errorCountKey);
                }
                InvalidateCode(verifier, plateForm, uniqueKey);
            }
            else
            {
                IncreaseErrorCount(verifier, errorCountKey);
            }
        }
예제 #3
0
        public static void InvalidateCode(CustomVerifier verifier, SystemPlatform plateForm, string uniqueKey)
        {
            string modelKey = verifier.GetVerifyModelKey(plateForm, uniqueKey);

            RedisHelper.KeyDelete(RedisDBIndex, modelKey);
        }
예제 #4
0
        public static T GetModel <T>(CustomVerifier verifier, SystemPlatform plateForm, string uniqueKey) where T : IVerified
        {
            string modelKey = verifier.GetVerifyModelKey(plateForm, uniqueKey);

            return(RedisHelper.Get <T>(RedisDBIndex, modelKey));
        }