Пример #1
0
        public void InitRecaptchaModel(ReCaptchaModel reCaptchaModel)
        {
            if (reCaptchaModel == null)
            {
                throw new ArgumentException("Can not init empty ReCaptcha model");
            }

            reCaptchaModel.RecaptchaPublicKey = m_config.PublicKey;
        }
Пример #2
0
        public ContentResult SiteVerify([FromBody] ReCaptchaModel model)
        {
            string reqData = string.Format(
                "secret={0}&response={1}&remoteip={2}",
                secret_key,
                model.ReCaptchaResponse,
                Request.HttpContext.Connection.RemoteIpAddress.ToString()
                );
            string resJson = SimpleHttpClient.PostAsync("https://www.google.com/recaptcha/api/siteverify", reqData, "application/x-www-form-urlencoded").Result;

            return(Content(resJson, "application/json"));
        }
Пример #3
0
        public static ReCaptchaModel Check(string response)
        {
            ReCaptchaModel result          = new ReCaptchaModel();
            const string   secret          = "your secret key here.";
            var            client          = new WebClient();
            var            reply           = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secret, response));
            var            captchaResponse = JsonConvert.DeserializeObject <ReCaptchaModel>(reply);

            if (!captchaResponse.Success)
            {
                if (captchaResponse.ErrorCodes.Count <= 0)
                {
                    captchaResponse.Result  = false;
                    captchaResponse.Message = "Error occured. Please try again";
                    return(captchaResponse);
                }
                var error = captchaResponse.ErrorCodes[0].ToLower();
                switch (error)
                {
                case ("missing-input-secret"):
                    captchaResponse.Result  = false;
                    captchaResponse.Message = "The secret parameter is missing.";
                    break;

                case ("invalid-input-secret"):
                    captchaResponse.Result  = false;
                    captchaResponse.Message = "The secret parameter is invalid or malformed.";
                    break;

                case ("missing-input-response"):
                    captchaResponse.Result  = false;
                    captchaResponse.Message = "The response parameter is missing.";
                    break;

                case ("invalid-input-response"):
                    captchaResponse.Result  = false;
                    captchaResponse.Message = "The response parameter is invalid or malformed.";
                    break;

                default:
                    captchaResponse.Result  = false;
                    captchaResponse.Message = "Error occured. Please try again";
                    break;
                }
            }
            else
            {
                captchaResponse.Result  = true;
                captchaResponse.Message = "Success";
            }
            return(captchaResponse);
        }
Пример #4
0
        public async Task <IActionResult> GetLogin(string user_id, string user_pw, string token)
        {
            if (User.Identity != null && User.Identity.IsAuthenticated == true)
            {
                Redirect("/");
            }

            try
            {
                var verify = await ReCaptchaModel.RecaptchaVerify(token);

                if (verify.Success == false || verify.Score < 0.3F)
                {
                    return(Json(new { msg = string.Join(',', verify.ErrorCodes) }));
                }

                var login = UserinfoModel.GetLogin(user_id, user_pw);

                if (login == null) //로그인 오류
                {
                    return(Redirect("/"));
                }

                var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme, ClaimTypes.Name, ClaimTypes.Role);

                identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, login.USER_ID));
                identity.AddClaim(new Claim(ClaimTypes.Name, login.USER_NAME));
                identity.AddClaim(new Claim(ClaimTypes.Role, login.ROLES));
                identity.AddClaim(new Claim("NextCheckDate", DateTime.Now.AddMinutes(1).ToString("yyyyMMddHHmmss"), typeof(DateTime).ToString()));

                var principal = new ClaimsPrincipal(identity);
                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties {
                    IsPersistent = false,                      //로그인 쿠키 영속성 (브라우저 종료시 유지) 여부
                    ExpiresUtc   = DateTime.UtcNow.AddDays(7), //7일간 미접속시 쿠키 만료
                    AllowRefresh = true,                       //갱신여부
                });

                return(Json(new { msg = "OK" }));
            }
            catch (Exception ex)
            {
                return(Json(new { msg = ex.Message }));
            }
        }
Пример #5
0
        public ActionResult FormPost(ContactModel model)
        {
            #region GoogleControl
            var            response     = Request["g-recaptcha-response"];
            ReCaptchaModel googleresult = ReCaptcha.Check(response);
            if (!googleresult.Result)
            {
                return(Json(new
                {
                    data = googleresult.Message,
                    success = false,
                }, JsonRequestBehavior.AllowGet));
            }
            #endregion

            if (!ModelState.IsValid)
            {
                //return error
            }
            //return success
            return(View());
        }
Пример #6
0
 /// <summary>
 /// Checks reCaptcha results.
 /// </summary>
 /// <returns></returns>
 public bool Validate(ReCaptchaModel model)
 {
     return(Validate(model.RecaptchaResponse));
 }