Exemplo n.º 1
0
        public FileContentResult MixVerifyCode()
        {
            string code = StringRandom.NumOrLetter();

            HttpContext.Session.SetString(StringSession.ArticleCommentKey, code.ToLower());
            return(File(code.CreateCheckCodeImage(), "image/gif"));
        }
        public static void Cleanup()
        {
            var randomizersList = new Dictionary <Type, IRandomizeble>();

            randomizersList[typeof(decimal)]  = new DecimalRandom();
            randomizersList[typeof(string)]   = new StringRandom();
            randomizersList[typeof(char)]     = new CharRandom();
            randomizersList[typeof(int)]      = new Int32Random();
            randomizersList[typeof(long)]     = new Int64Random();
            randomizersList[typeof(bool)]     = new BoolRandom();
            randomizersList[typeof(byte)]     = new ByteRandom();
            randomizersList[typeof(sbyte)]    = new SByteRandom();
            randomizersList[typeof(float)]    = new FloatRandom();
            randomizersList[typeof(double)]   = new DoubleRandom();
            randomizersList[typeof(short)]    = new Int16Random();
            randomizersList[typeof(uint)]     = new UInt32Random();
            randomizersList[typeof(ushort)]   = new UInt16Random();
            randomizersList[typeof(ulong)]    = new UInt64Random();
            randomizersList[typeof(DateTime)] = new DateTimeRandom();
            UniversalRandom.AddRandomizers(randomizersList);

            UniversalRandom.AddInterceptors(new List <IInterceptor>
            {
                new ListInterceptor(),
                new EnumInterceptor(),
                new ArrayInterceptor()
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// 发送注册邮箱验证码
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public async Task SendRegisterCode(string email)
        {
            string ipEmail = $"{_clientInfoProvider.ClientIpAddress}_{email}";
            var    code    = await _cacheManager.GetCache(UserCacheNames.CacheRegisterEmailCode)
                             .GetAsync(ipEmail, () =>
            {
                return(Task.FromResult(StringRandom.NumOrLetter(5)));
            });

            //Send a notification email
            _emailSender.Send(
                to: email,
                subject: "验证码提醒",
                body: $"验证码为: {code};有效期为15分钟",
                isBodyHtml: true
                );
        }
Exemplo n.º 4
0
        public Task <TMJsonResponse> SendAsync(TMJsonRequest request, bool ignoreAck = false, int timeLimitForDefaultResult = 3000)
        {
            try
            {
                var jsonObj = TMEncoding.Instance.Serialize(request);
                var json    = TMEncoding.Instance.Deserialize(jsonObj) as Dictionary <string, object>;
                var tcs     = new TaskCompletionSource <TMJsonResponse>();
                var qId     = StringRandom.RandomHexString(8);
                json["si"] = qId;

                var jsonStringText = TMEncoding.Instance.Serialize(json);

                EventHandler <TMJsonResponse> onResponse = null;

                onResponse = (sender, response) =>
                {
                    if (response.CommandId == qId)
                    {
                        if (!ignoreAck || response.Results != null)
                        {
                            OnResponse -= onResponse;
                            if (tcs.Task.IsCanceled || tcs.Task.IsCompleted)
                            {
                                return;
                            }
                            tcs.SetResult(response);
                        }
                    }
                };

                this.SendAsync(jsonStringText).Wait();
                OnResponse += onResponse;
                tcs.SetDefaultResult(new TMJsonResponse(), timeLimitForDefaultResult, () =>
                {
                    OnResponse -= onResponse;
                });
                return(tcs.Task);
            }
            catch (TaskCanceledException tce)
            {
                return(Task.FromResult(new TMJsonResponse()));
            }
        }
        static UniversalRandom()
        {
            _randomizers[typeof(decimal)]  = new DecimalRandom();
            _randomizers[typeof(string)]   = new StringRandom();
            _randomizers[typeof(char)]     = new CharRandom();
            _randomizers[typeof(int)]      = new Int32Random();
            _randomizers[typeof(long)]     = new Int64Random();
            _randomizers[typeof(bool)]     = new BoolRandom();
            _randomizers[typeof(byte)]     = new ByteRandom();
            _randomizers[typeof(sbyte)]    = new SByteRandom();
            _randomizers[typeof(float)]    = new FloatRandom();
            _randomizers[typeof(double)]   = new DoubleRandom();
            _randomizers[typeof(short)]    = new Int16Random();
            _randomizers[typeof(uint)]     = new UInt32Random();
            _randomizers[typeof(ushort)]   = new UInt16Random();
            _randomizers[typeof(ulong)]    = new UInt64Random();
            _randomizers[typeof(DateTime)] = new DateTimeRandom();

            _interceptors.Add(new ArrayInterceptor());
            _interceptors.Add(new EnumInterceptor());
            _interceptors.Add(new ListInterceptor());
        }
Exemplo n.º 6
0
        public string Build()
        {
            string randomStr = StringRandom.GetRandomAlphanumericString(8);

            return(randomStr + "@gmail.com");
        }
 public SlarkWebSocketClientConnection(SlarkWebSokcetServer server, WebSocket webSocket)
 {
     Server    = server;
     WebSocket = webSocket;
     Id        = StringRandom.RandomHexString(16);
 }