public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { try { using (WebClient client = new WebClient()) { var response = client.DownloadString( string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", "6Lf_UBgUAAAAAGHsBD8306dRAc6gHmzSR1HEUTqe", Request.Params["g-Recaptcha-Response"])); ReCaptchaResult reCaptchaResult = JsonConvert.DeserializeObject <ReCaptchaResult>(response); if (!reCaptchaResult.Success) { ModelState.AddModelError("reCaptcha", "Bot olmadığınızı kanıtlayın."); return(View(model)); } } } catch (Exception exception) { ModelState.AddModelError("reCaptcha", exception); return(View(model)); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public static bool ValidateReCaptcha(string key, string responsee) { using (HttpClient client = new HttpClient()) { var getTask = client.GetAsync($"https://www.google.com/recaptcha/api/siteverify?secret={key}&response={responsee}"); Task.WaitAll(getTask); HttpResponseMessage response = getTask.Result; var readTask = response.Content.ReadAsStringAsync(); Task.WaitAll(readTask); string resultJson = readTask.Result; ReCaptchaResult result = NetJSON.NetJSON.Deserialize <ReCaptchaResult>(resultJson); return(result.success); } }