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)); }
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); } }
public static void InvalidateCode(CustomVerifier verifier, SystemPlatform plateForm, string uniqueKey) { string modelKey = verifier.GetVerifyModelKey(plateForm, uniqueKey); RedisHelper.KeyDelete(RedisDBIndex, modelKey); }
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)); }