Beispiel #1
0
        public ActionResult _ManagerResetUserPassword(ManagerResetUserPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            var user = UserManager.FindByName(model.UserName);
            if (user == null)
            {
                // 不顯示使用者不存在
                ModelState.AddModelError("NoUserFound", "找不到使用者資料");
                return View(model);
            }

            // 原本的
            //var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);

            // 刪除原本的密碼後再重新設定
            UserManager.RemovePassword(user.Id);
            var result = UserManager.AddPassword(user.Id, model.Password);

            if (result.Succeeded)
            {
                return RedirectToAction("Index", "Members");
            }
            AddErrors(result);
            return View();
        }
Beispiel #2
0
        //
        // GET: /Account/ResetPassword
        public ActionResult _ManagerResetUserPassword(string userName)
        {
            var user = UserManager.FindByName(userName);
            ManagerResetUserPasswordViewModel resetPasswordViewModel = new ManagerResetUserPasswordViewModel()
            {
                UserName = loginUser.UserName,
                Password = null
            };

            return View(resetPasswordViewModel);
        }