Esempio n. 1
0
        public CheckCodeOutput Check(GeetestCheckInput input)
        {
            GeetestLib geetest = GetGeetestLib();
            int        result  = geetest.enhencedValidateRequest(input.Challenge, input.Validate, input.Seccode);

            if (result == 1)
            {
                var verifcationCache = new VerifcationCache()
                {
                    VerifcationType = VerifcationType.Geetest,
                    Code            = Guid.NewGuid().ToString()
                };
                SetCache(verifcationCache);
                return(new CheckCodeOutput()
                {
                    Success = true,
                    Token = verifcationCache.Code
                });
            }
            else
            {
                return(new CheckCodeOutput()
                {
                    Success = false
                });
            }
        }
Esempio n. 2
0
        public string GetCaptcha()
        {
            var verifcationCache = new VerifcationCache()
            {
                VerifcationType = VerifcationType.GeetestNow
            };

            SetCache(verifcationCache);

            GeetestLib geetest        = GetGeetestLib();
            Byte       gtServerStatus = geetest.preProcess();

            return(geetest.getResponseStr());
        }
        private void SetCache(VerifcationCache verifcationCache)
        {
            var hasClientToken = HttpContext.Current.Request.Cookies.TryGetValue("ClientToken", out string requestCookie);

            if (!hasClientToken)
            {
                requestCookie = Guid.NewGuid().ToString("N");
                HttpContext.Current.Response.Cookies.Append("ClientToken", requestCookie);
            }
            if (verifcationCache != null)
            {
                _cacheManager.GetCache("ClientToken").Set(requestCookie, verifcationCache);
            }
            else
            {
                _cacheManager.GetCache("ClientToken").Remove(requestCookie);
            }
        }
Esempio n. 4
0
        private void SetCache(VerifcationCache verifcationCache)
        {
            var requestCookie = HttpContext.Current.Request.Cookies.Get("ClientToken");
            var clientToken   = "";

            if (requestCookie == null)
            {
                clientToken = Guid.NewGuid().ToString("N");
                var cookie = new HttpCookie("ClientToken", clientToken);
                HttpContext.Current.Response.SetCookie(cookie);
            }
            else
            {
                clientToken = requestCookie.Value;
            }
            if (verifcationCache != null)
            {
                _cacheManager.GetCache("ClientToken").Set(clientToken, verifcationCache);
            }
            else
            {
                _cacheManager.GetCache("ClientToken").Remove(clientToken);
            }
        }