/// <summary>
        /// 验证短信验证码
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="smsCode"></param>
        /// <returns></returns>
        public async Task VerifySmsCodeAsync(string mobile, string smsCode)
        {
            // 配置中心验证是否验证码
            var isVerify = _config.StringGet("IsVerifySmsCode");

            if (!isVerify.IsEmpty() && isVerify == "2")
            {
                return;
            }
            // keys
            var errCountKey  = string.Format(CacheKeys.SmsCodeVerifyErr, mobile);
            var loginCodeKey = string.Format(CacheKeys.SmsCodeLoginCode, mobile);
            var sendCountKey = string.Format(CacheKeys.SmsCodeSendIdentity, mobile);

            var rediscontect = _config.StringGet("RedisDefaultServer");
            var redis        = _redisClient.GetDatabase(rediscontect, 5);

            // 错误次数判断
            var errCount = await redis.StringGetAsync(errCountKey);

            if (!errCount.IsNullOrEmpty && errCount.SafeString().ToInt() > 5)
            {
                throw new BucketException("GO_0005055", "登陆错误次数过多,请30分钟后再试");
            }

            // 短信验证码验证
            var verifyValue = await redis.StringGetAsync(loginCodeKey);

            if (string.IsNullOrWhiteSpace(verifyValue))
            {
                throw new BucketException("GO_0005014", "验证码不存在");
            }

            if (verifyValue.SafeString().ToLower() != smsCode.SafeString().ToLower())
            {
                // 记录错误次数,30分钟
                await redis.StringSetAsync(errCountKey, (errCount.IsNullOrEmpty ? 1 : errCount.SafeString().ToInt() + 1), new TimeSpan(0, 30, 0));

                // 抛出异常
                throw new BucketException("GO_0005015", "验证码错误");
            }
            // 清除次数
            var delKeys = new StackExchange.Redis.RedisKey[] { errCountKey, loginCodeKey, sendCountKey };
            await redis.KeyDeleteAsync(delKeys);
        }
        /// <summary>
        /// Obtenir du cache partagé
        /// </summary>
        /// <param name="DirectInvoiceid"></param>
        /// <returns></returns>
        public DirectInvoice GetDirectInvoice(string iddirectinvoice)
        {
            DirectInvoice retour = null;

            try
            {
                // Obtien d'abord l'objet sur MemCached si Existe
                if (env != null)
                {
                    StackExchange.Redis.ConfigurationOptions redisconfig = new StackExchange.Redis.ConfigurationOptions();
                    redisconfig.EndPoints.Add("22ec9a54-2921-43af-a4e9-9b1e7aff2b9b.pdb.ovh.net", 21784);
                    redisconfig.Password = "******";

                    StackExchange.Redis.ConnectionMultiplexer redis   = StackExchange.Redis.ConnectionMultiplexer.Connect(redisconfig);
                    StackExchange.Redis.IDatabase             redisDb = redis.GetDatabase();


                    StackExchange.Redis.RedisKey key = iddirectinvoice;

                    StackExchange.Redis.RedisValue val = redisDb.StringGet(key, StackExchange.Redis.CommandFlags.None);
                    if (!string.IsNullOrWhiteSpace(val))
                    {
                        retour = new DirectInvoice();
                        retour.FromStringData(val);
                    }
                }

                // sinon regarde en base
                if (retour == null)
                {
                    Dictionary <string, object> ins = new Dictionary <string, object>();
                    ins.Add("iddirectinvoice", iddirectinvoice);
                    retour = this.GetOneDefault <DirectInvoice>(ins);
                }
                return(retour);
            }
            catch (Exception ex)
            {
                throw new Exception("GetDirectInvoice " + ex.Message, ex);
            }
        }
        /// <summary>
        /// enregistre en base et dans le cache partagé
        /// </summary>
        public void SaveDirectInvoice(DirectInvoice directinvoice)
        {
            try
            {
                // Enregistrement des clef (données persistantes) en bases
                System.Data.DataRowState rowstate = directinvoice.GetRow().RowState;
                if (rowstate == System.Data.DataRowState.Detached || rowstate == System.Data.DataRowState.Added)
                {
                    this.InsertBubble(directinvoice, true, false);
                }
                else
                {
                    this.SaveBubble(directinvoice);
                }

                // Enregistrement des données non persistantes sur MemCached
                if (env != null)
                {
                    StackExchange.Redis.ConnectionMultiplexer redis   = StackExchange.Redis.ConnectionMultiplexer.Connect(GetRedisConfig());
                    StackExchange.Redis.IDatabase             redisDb = redis.GetDatabase();

                    StackExchange.Redis.RedisValue val = directinvoice.ToStringData();
                    StackExchange.Redis.RedisKey   key = directinvoice.IdDirectInvoice;
                    redisDb.StringSet(key, val, null, StackExchange.Redis.When.Always, StackExchange.Redis.CommandFlags.None);



                    // redng75Oj82p

                    // !!! stocker dans memecached
                }
            }
            catch (Exception ex)
            {
                throw new Exception("SaveDirectInvoice " + ex.Message, ex);
            }
        }
Ejemplo n.º 4
0
 public RedisXmlRepository(System.Func <StackExchange.Redis.IDatabase> databaseFactory, StackExchange.Redis.RedisKey key)
 {
 }
Ejemplo n.º 5
0
 public static Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder PersistKeysToStackExchangeRedis(this Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder builder, System.Func <StackExchange.Redis.IDatabase> databaseFactory, StackExchange.Redis.RedisKey key)
 {
     throw null;
 }
Ejemplo n.º 6
0
 public static Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder PersistKeysToStackExchangeRedis(this Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder builder, StackExchange.Redis.IConnectionMultiplexer connectionMultiplexer, StackExchange.Redis.RedisKey key)
 {
     throw null;
 }