示例#1
0
        public async Task <IActionResult> PasswordReset([FromForm] ResetPasswordInputModel model)
        {
            var vm = _account.BuildResetPasswordViewModel(model, false);

            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            IdentityExpressUser identityExpressUser = await _userManager.GetUserAsync(User);

            var result = await _userManager.ResetPasswordAsync(identityExpressUser, model.Token, model.Password);

            if (result.Succeeded)
            {
                result = await _userManager.UpdateAsync(identityExpressUser);
            }

            if (!result.Succeeded)
            {
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError("", item.Description);
                }
            }

            vm = _account.BuildResetPasswordViewModel(model, result.Succeeded);

            return(View(vm));
        }
示例#2
0
        public ResetPasswordViewModel BuildResetPasswordViewModel(ResetPasswordInputModel model, bool success)
        {
            ResetPasswordViewModel newModel = new ResetPasswordViewModel
            {
                IsSuccess       = success,
                Password        = model.Password,
                ConfirmPassword = model.ConfirmPassword,
                Email           = model.Email,
                Token           = model.Token,
            };

            return(newModel);
        }
示例#3
0
        public async Task <IActionResult> ResetPassword(ResetPasswordInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(new ResetPasswordViewModel {
                    Error = "Password values must match"
                }));
            }

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

            var resetPassResult = await _userManager.ResetPasswordAsync(user, model.Token, model.Password);

            if (!resetPassResult.Succeeded)
            {
                return(View(new ResetPasswordViewModel {
                    Error = resetPassResult.Errors.First().Description
                }));
            }

            return(View("ResetPasswordSuccess"));
        }