Exemplo n.º 1
0
        public JsonResult ValidateCaptcha(string dataToken)
        {
            try
            {
                //AntiForgery.Validate(Request.Cookies[AntiForgeryConfig.CookieName].Value, Request.Headers["__RequestVerificationToken"]);
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.google.com/recaptcha/api/siteverify?secret=6LdrXwkTAAAAALd-B-IipgpHQNjSbri6ioduA2Zt&response=" + dataToken);
                using (WebResponse wResponse = req.GetResponse())
                {
                    using (StreamReader readStream = new StreamReader(wResponse.GetResponseStream()))
                    {
                        string jsonResponse = readStream.ReadToEnd();

                        GoogleCaptcha captchaResponse = JsonConvert.DeserializeObject <GoogleCaptcha>(jsonResponse);

                        //if(captchaResponse.success)
                        //{
                        //    Response.StatusCode = 200;
                        //}

                        return(Json(captchaResponse));
                    }
                }
            }
            catch (Exception ex)
            {
                //logar
                return(Json(new GoogleCaptcha {
                    success = false
                }));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            var captchaResponse = Request.Form["g-Recaptcha-Response"];
            var isValid         = GoogleCaptcha.Validate(captchaResponse);

            if (isValid)
            {
                var user = await userManager.FindByNameAsync(model.username);

                if (user != null)
                {
                    var result = await signInManager.PasswordSignInAsync(user, model.password, false, false);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
            else
            {
                ViewBag.Message = "Lütfen Ben Robot Değilim Seçeneğini İşaretleyin";
            }
            return(View("Login", "Account"));
        }
Exemplo n.º 3
0
        public static GoogleCaptcha ValidateCaptcha(string token)
        {
            var secretKey = ConfigurationManager.AppSettings["GoogleCaptchaSecretKey"];                             //secret key
            var url       = $"https://www.google.com/recaptcha/api/siteverify?secret={secretKey}&response={token}"; // url

            HttpClient httpClient = new HttpClient();

            var res = httpClient.GetAsync(url).Result;

            if (res.StatusCode != HttpStatusCode.OK)
            {
                return(null);
            }

            //response
            string response = res.Content.ReadAsStringAsync().Result;

            if (string.IsNullOrWhiteSpace(response))
            {
                return(null);
            }

            GoogleCaptcha googleCaptcha = JsonConvert.DeserializeObject <GoogleCaptcha>(response);

            return(googleCaptcha);
        }
Exemplo n.º 4
0
        public ActionResult LogIn(LogInViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            GoogleCaptcha googleCaptcha = ValidateCaptcha(model.CaptchaToken);

            return(Json(new { googleCaptcha }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Register(RegisterViewModel viewModel)
        {
            string recaptchaMessage = Request.Form[GoogleCaptcha.GoogleRequestKey];
            var    recaptcha        = new GoogleCaptcha(recaptchaMessage);

            if (recaptcha.Success)
            {
                if (ModelState.IsValid)
                {
                    var userOrganization = new OrganizationDTO
                    {
                        Address      = viewModel.Address.ToDTO(),
                        ContactPoint = viewModel.ContactPoint.ToDTO(),
                        Name         = viewModel.Company.LegalName,
                        Kind         = viewModel.Kind,
                        NameEn       = viewModel.Company.LegalNameEn,
                        Identifier   = new IdentifierDTO
                        {
                            Id          = viewModel.Company.Id,
                            Scheme      = viewModel.Company.Scheme,
                            Uri         = viewModel.Company.Uri,
                            LegalName   = viewModel.Company.LegalName,
                            LegalNameEn = viewModel.Company.LegalNameEn
                        }
                    };

                    var provider           = DependencyResolver.Current.GetService <ITenderProvider>();
                    var userOrganizationId = await provider.AddUserOrganization(userOrganization);

                    var user = new ApplicationUser
                    {
                        UserName           = viewModel.Email,
                        Email              = viewModel.Email,
                        PhoneNumber        = viewModel.Phone,
                        UserOrganizationId = userOrganizationId
                    };
                    var result = await UserManager.CreateAsync(user, viewModel.Password);

                    if (result.Succeeded)
                    {
                        if (await SendConfirmationEmail(user))
                        {
                            return(DisplayConfirmation(GlobalRes.Confirmation,
                                                       string.Format(GlobalRes.ConfirmationEmailSent, user.Email),
                                                       GlobalRes.ConfirmationEmailSentDescr));
                        }
                        else
                        {
                            return(DisplayError(null,
                                                GlobalRes.ConfirmationEmailSendError,
                                                GlobalRes.TrayAgainLater));
                        }
                    }
                    AddErrors(result);
                    await provider.DeleteUserOrganization(userOrganizationId);
                }
            }
            else
            {
                ModelState.AddModelError(nameof(viewModel.CaptchaSuccess), recaptcha.ErrorMessage);
            }

            var schemesProvider = DependencyResolver.Current.GetService <ISchemesProvider>();
            var schemeList      = (await schemesProvider.GetIdentifierSchemes())
                                  .Select(m => new SelectListItem {
                Value = m, Text = m
            });
            var schemes = new List <SelectListItem>(schemeList);
            var uaEdr   = schemes.FirstOrDefault(m => m.Value == "UA-EDR");

            uaEdr.Selected      = true;
            ViewData["Schemes"] = schemes;
            return(View(viewModel));
        }