private async Task <bool> ValidateAttemptOfPasswordReset(PasswordResetCodeModel model, string userId)
        {
            var result = await _passwordResetManger.ValidateRequestAsync(userId, model.Code);

            if (result.NoRequest)
            {
                ModelState.AddModelError("", ApplicationResources.UserInterface.PasswordReset.NoRequest);
                return(false);
            }

            if (result.Blocked)
            {
                ModelState.AddModelError("", ApplicationResources.UserInterface.PasswordReset.Blocked);
                return(false);
            }

            if (result.Expired)
            {
                ModelState.AddModelError("", ApplicationResources.UserInterface.PasswordReset.Expired);
                return(false);
            }

            if (!result.Success)
            {
                ModelState.AddModelError("", ApplicationResources.UserInterface.PasswordReset.InvalidCode);
                return(false);
            }

            if (result.Success)
            {
                return(true);
            }

            ModelState.AddModelError("", ApplicationResources.UserInterface.PasswordReset.Exception);
            return(false);
        }
        public async Task <IActionResult> VerifyCode(PasswordResetCodeModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.EmailAddress);

                if (user != null)
                {
                    if (Equals(model.NewPassword, model.NewPassword2))
                    {
                        var ok = await ValidateAttemptOfPasswordReset(model, user.Id);

                        if (ModelState.IsValid && ok)
                        {
                            IdentityResult validEmail = await _userValidator.ValidateAsync(_userManager, user);

                            if (!validEmail.Succeeded)
                            {
                                this.AddErrorsFromResult(validEmail);
                            }
                            else
                            {
                                var validPassword = await _passwordValidator.ValidateAsync(_userManager, user, model.NewPassword);

                                if (validPassword.Succeeded)
                                {
                                    user.PasswordHash = _passwordHasher.HashPassword(user, model.NewPassword);
                                    if (validEmail.Succeeded && model.NewPassword != string.Empty && validPassword.Succeeded)
                                    {
                                        IdentityResult result = await _userManager.UpdateAsync(user);

                                        if (result.Succeeded)
                                        {
                                            return(RedirectToAction("Login", "Login"));
                                        }
                                        else
                                        {
                                            this.AddErrorsFromResult(result);
                                        }
                                    }
                                }
                                else
                                {
                                    this.AddErrorsFromResult(validPassword);
                                }
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", ApplicationResources.UserInterface.Common.NotEqualPasswords);
                    }
                }
                else
                {
                    ModelState.AddModelError("", ApplicationResources.UserInterface.Common.UserDoNotExist);
                }
            }

            return(View(model));
        }