Exemple #1
0
        public async Task <IActionResult> ChangePass(ChangePassUserView changePassView)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = _userManager.FindByIdAsync(changePassView.Id).Result;
                if (user != null)
                {
                    var result = await _userManager.ChangePasswordAsync(user, changePassView.CurrentPassword, changePassView.NewPassword);

                    if (result.Succeeded)
                    {
                        await _userManager.UpdateAsync(user);

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        foreach (var item in result.Errors)
                        {
                            ModelState.AddModelError("", item.Description);
                        }
                    }
                }
                else
                {
                    return(View());
                }
            }

            return(View());
        }
Exemple #2
0
        public IActionResult ChangePass(string id)
        {
            ApplicationUser user = _userManager.FindByIdAsync(id).Result;

            if (user == null)
            {
                ModelState.AddModelError("", "Tài khoản này không tồn tại");
                return(RedirectToAction("Index", "Home"));
            }
            ChangePassUserView changePassUserView = new ChangePassUserView()
            {
                Id = user.Id,
            };

            return(View(changePassUserView));
        }