Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!_captcha.Validate(Input.CaptchaCode, HttpContext.Session))
            {
                ModelState.AddModelError("Input.CaptchaCode", "Captcha code is not correct.");
                return(Page());
            }

            var user = await _userManager.FindByEmailAsync(Input.Email);

            if (user == null)
            {
                // Don't reveal that the user does not exist
                return(RedirectToPage("./ResetPasswordConfirmation"));
            }


            var result = await _userManager.ResetPasswordAsync(user, Input.Code, Input.Password);

            if (result.Succeeded)
            {
                string key = _config.GetSection("md5password").GetSection("Key").Value;

                if (string.IsNullOrEmpty(key))
                {
                    try
                    {
                        await _queryHelper.ResetPaassword(user.Login, Input.Password);
                    }
                    catch (SqlException e)
                    {
                        Console.WriteLine("Errooooor: " + e.Message);
                    }
                }
                else
                {
                    try
                    {
                        await _queryHelper.ResetPaassword(user.Login, Input.Password, md5password : HelperFunctions.hCrypt(Input.Password, key));
                    }
                    catch (SqlException e)
                    {
                        Console.WriteLine("Errooooor: " + e.Message);
                    }
                }



                return(RedirectToPage("./ResetPasswordConfirmation"));
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }
            return(Page());
        }