Ejemplo n.º 1
0
        public async Task <IActionResult> Register(RegisterViewModel registerVM)
        {
            var response = Request.Form["g-recaptcha-response"];
            //var privateKey = "6LenDnMUAAAAAMt0z9La7MUuIUACu4N3hpNavOeZ";
            var captchaStatus = ReCaptcha.ReCaptchaPassed(response, ReCaptcha.PrivateKey);

            if (ModelState.IsValid && captchaStatus)
            {
                var isUserNameExist = userManager.FindByNameAsync(registerVM.UserName).Result;
                if (isUserNameExist != null)
                {
                    return(Json(new { state = "UserNameExist" }));
                }
                var isMailExist = userManager.FindByEmailAsync(registerVM.Mail).Result;
                if (isMailExist != null)
                {
                    return(Json(new { state = "MailExist" }));
                }

                var user = new User
                {
                    FullName        = registerVM.FullName,
                    UserName        = registerVM.UserName,
                    Email           = registerVM.Mail,
                    Gender          = registerVM.Gender,
                    CreatedDateTime = DateTime.Now
                };
                var result = await userManager.CreateAsync(user, registerVM.Password);

                if (result.Succeeded)
                {
                    return(Json(new { state = "Ok" }));
                }
                else
                {
                    return(Json(new { state = "NOk" }));
                }
            }
            else if (!captchaStatus)
            {
                ViewBag.CaptchaEmpty = "CaptchaEmpty";
                return(Json(new { state = "CaptchaError" }));
            }
            return(View());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Register(RegisterViewModel registerVM)
        {
            var response      = Request.Form["g-recaptcha-response"];
            var privateKey    = _configuration["GoogleRecaptcha"];
            var captchaStatus = ReCaptcha.ReCaptchaPassed(response, privateKey);


            if (ModelState.IsValid && captchaStatus)
            {
                //is private part of project
                //related to token - jwt web api
                return(Json(new { state = "Ok" }));
            }
            else if (!captchaStatus)
            {
                ViewBag.CaptchaEmpty = "CaptchaEmpty";
                return(Json(new { state = "CaptchaError" }));
            }
            return(View());
        }