Exemplo n.º 1
0
        public async Task <IActionResult> ResetPassword(ResetPasswordViewModel model)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Profile"));
            }

            UserModel user = await ManageUser.FindByEmailAsync(model.Email);

            if (user != null)
            {
                var passwordValidator = new PasswordValidator <UserModel>();
                var result            = await passwordValidator.ValidateAsync(ManageUser, null, model.Password);

                if (result.Succeeded)
                {
                    result = await ManageUser.ResetPasswordAsync(user, model.Token, model.Password);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Login"));
                    }
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.TryAddModelError(error.Code, error.Description);
                    }

                    ViewBag.token = model.Token;
                    ViewBag.email = model.Email;

                    return(View("ResetPassword"));
                }
            }

            return(View("Verify"));
        }