public IActionResult EditUserPassword(Guid id) { EditUserPasswordModel model = new EditUserPasswordModel(); var entity = _userService.FindById(id); if (entity != null) { model.SystemUserId = id; model.Name = entity.Name; model.NewPassword = string.Empty; } else { return(NotFound()); } return(View(model)); }
public IActionResult EditUserPassword(EditUserPasswordModel model) { if (model.NewPassword.Length < 6 || model.NewPassword.Length > 16) { ModelState.AddModelError("newpassword", T["user_password_lengthrange"]); } if (!model.NewPassword.IsCaseInsensitiveEqual(model.ConfirmPassword)) { ModelState.AddModelError("newpassword", T["user_password_notequal"]); } if (ModelState.IsValid) { var user = _userService.FindById(model.SystemUserId); string password = SecurityHelper.MD5(model.NewPassword + user.Salt); bool result = _userService.Update(x => x .Set(n => n.Password, password) .Where(n => n.SystemUserId == model.SystemUserId) ); return(result.UpdateResult(T)); } return(UpdateFailure(GetModelErrors())); }
public virtual ActionResult EditUserPassword(int userId, EditUserPasswordModel viewModel) { User user = _userRepo.GetUserById(userId); if (user == null) { return PermanentRedirectToAction(MVC.Error.InvalidAction()); } Mapper.CreateMap<EditUserPasswordModel, User>(); Mapper.Map(viewModel, user); if (ModelState.IsValid) { user.Password = Auth.HashPassword(user.Password, user.Salt); _userRepo.Save(user); return RedirectToAction(MVC.Admin.Management.ViewUser(userId)); } viewModel.User = _userRepo.GetUserById(userId); return View(viewModel); }