コード例 #1
0
ファイル: AccountController.cs プロジェクト: Tiktack/ETT
        public async Task <IActionResult> ChangePassword(ChangeAccountPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _userManager.FindByIdIntAsync(CurrentUserId ?? 0);

                if (user != null)
                {
                    IdentityResult result =
                        await _userManager.ChangePasswordNVAsync(user, model.OldPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        foreach (var error in result.Errors)
                        {
                            ModelState.AddModelError(string.Empty, error.Description);
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Пользователь не найден");
                }
            }

            return(View(model));
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: Tiktack/ETT
        public async Task <IActionResult> ChangePassword()
        {
            User user = await _userManager.FindByIdIntAsync(CurrentUserId ?? 0);

            if (user == null)
            {
                return(NotFound());
            }

            ChangeAccountPasswordViewModel model = new ChangeAccountPasswordViewModel {
                Email = user.Email
            };

            return(View(model));
        }
コード例 #3
0
        public async Task <ActionResult <string> > ChangePassword(
            ChangeAccountPasswordViewModel model)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var result = await _userManager.ChangePasswordAsync(
                user,
                model.CurrentPassword,
                model.NewPassword
                );

            if (!result.Succeeded)
            {
                return(BadRequest(
                           new ErrorDetails(result.Errors())
                           ));
            }

            return(NoContent());
        }