public async Task <JsonResult> ModifyPassword([FromBody] ModifyPwdModel model) { var rs = new ResultMsg() { Code = 0 }; if (!ModelState.IsValid) { foreach (var key in ModelState.Keys) { var modelstate = ModelState[key]; if (modelstate.Errors.Any()) { rs.Msg += modelstate.Errors.FirstOrDefault().ErrorMessage + ";"; } } return(Json(rs)); } if (model.NewPassword != model.Confirm_NewPassword) { rs.Msg = "两次输入的密码不一致"; return(Json(rs)); } rs = await _service.ModifyPassword(model.PKID, model.OldPassword, model.NewPassword); return(Json(rs)); }
public ActionResult ModifyPwd(ModifyPwdModel model) { //加密 model.NewPwd = model.NewPwdConfirm = Utility.EncryptHelper.MD5Encrypt(model.NewPwd); //model.OldPwd = Utility.EncryptHelper.MD5Encrypt(model.OldPwd); //取得当前用户 var sessionUser = Session["user"] as User; using (TCTEContext db = new TCTEContext()) { int userId = int.Parse(Request.QueryString["userId"]); var user = db.Users.Where(u => u.Id == userId).SingleOrDefault(); //校验原密码 if (!RoleHelper.IsInRole(SystemRole.SUPER_ADMIN)) { if (user.Password != model.OldPwd) { ModelState.AddModelError("", "原密码不正确"); return(View()); } } //修改密码 user.Password = model.NewPwdConfirm; db.SaveChanges(); return(Redirect("/User/index")); } }
public ActionResult ModifyPwd(ModifyPwdModel model) { if (ModelState.IsValid) { //加密 model.NewPwd = model.NewPwdConfirm = Utility.EncryptHelper.MD5Encrypt(model.NewPwd); model.OldPwd = Utility.EncryptHelper.MD5Encrypt(model.OldPwd); //取得当前用户 var sessionUser = Session["user"] as User; using (TCTEContext db = new TCTEContext( )) { var user = db.Users.Find(sessionUser.Id); //校验原密码 if (user.Password != model.OldPwd) { ModelState.AddModelError("", "原密码不正确"); return(View( )); } //修改密码 user.Password = model.NewPwdConfirm; db.SaveChanges( ); return(RedirectToAction("LogOut")); } } return(View( )); }
public async Task <ActionResult> ModifyPwd(ModifyPwdModel model) { var result = new JsonModel(); var user = await UsersRepository.GetByIdAsync(User.UserInfo.UserId); if (user == null) { result.statusCode = 300; result.message = "该条数据不存在,请刷新重试!"; return(Json(result)); } //原密码不正确 if (!user.Password.Equals(HashUtils.HashPasswordWithSalt(model.OldPwssword, user.PasswordSalt))) { ModelState.AddModelError("OldPwssword", "原密码输入有误,请重新输入!"); } if (!ModelState.IsValid) { result.GetError(ModelState); return(Json(result)); } if (!string.IsNullOrEmpty(model.Password)) { user.PasswordSalt = HashUtils.GenerateSalt(); user.Password = HashUtils.HashPasswordWithSalt(model.Password, user.PasswordSalt); } await LogRepository.Insert(TableSource.Users, OperationType.Update, "修改密码", user.Id); await UsersRepository.SaveAsync(user); result.Data = user; result.message = "保存成功!"; return(Json(result)); }
public async Task <ActionResult> ModifyPwd() { var model = new ModifyPwdModel(); var user = await UsersRepository.GetByIdAsync(User.UserInfo.UserId); if (user == null) { var json = new JsonModel { message = "记录不存在了", statusCode = 300 }; return(Json(json, JsonRequestBehavior.AllowGet)); } return(PartialView(model)); }
public IHttpActionResult ModifyPwd([FromBody] RequestModel req) { try { ModifyPwdModel model = new ModifyPwdModel(); var parameters = Common.AesDecryp.GetAesDecryp(req.data, req.secret); model.ID = Convert.ToInt32(parameters["ID"]); model.NewPwd = Common.MD5.Encrypt(parameters["NewPwd"], 32); //加密后 model.OldPwd = Common.MD5.Encrypt(parameters["OldPwd"], 32); //加密后 model.RepeatPwd = Common.MD5.Encrypt(parameters["RepeatPwd"], 32); //加密后 if ((!string.IsNullOrEmpty(model.NewPwd) && !string.IsNullOrEmpty(model.OldPwd) && model.ID != 0)) { if (model.NewPwd == model.RepeatPwd) { using (dbDataContext db = new dbDataContext()) { var list = db.Users.Where(x => x.ID == model.ID).FirstOrDefault(); if (list != null) { if (list.Pwd == model.OldPwd) { list.Pwd = model.NewPwd; db.SubmitChanges(); return(Json(new { state = 1, msg = "修改成功" })); } return(Json(new { state = 0, msg = "旧密码不正确" })); } return(Json(new { state = 0, msg = "用户不存在" })); } } return(Json(new { state = 0, msg = "两次密码不一样" })); } return(Json(new { state = 0, msg = "密码或ID为空" })); } catch (Exception ex) { throw ex; } }