public ActionResult ChangePassword(ChangePasswordViewModel model) { try { if (String.IsNullOrWhiteSpace(model.Password) || String.IsNullOrWhiteSpace(model.NewPassword) || String.IsNullOrWhiteSpace(model.PasswordConfirm)) { throw new Exception("打 * 的为必填字段,请正确填写完毕再提交。"); } if (!model.NewPassword.Equals(model.PasswordConfirm)) { throw new Exception("两次输入的密码不一致,请重新输入。"); } UserBusiness ub = new UserBusiness(); ub.ChangePassword(SessionManager.User.LoginName, model.Password, model.NewPassword); ModelState.AddModelError("", "密码修改成功!"); return View("Password", model); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return View("Password", model); } }
public ChangePasswordResponse Login([FromBody]ChangePasswordRequest request,string userid) { if (request == null) { throw new BadRequestException(); } var response = new ChangePasswordResponse(); UserBusiness ub = new UserBusiness(); try { if ("Administrator".Equals(userid, StringComparison.OrdinalIgnoreCase)) { response.IsSuccess = false; response.Message = "不能修改Administrator密码。"; return response; } var user = ub.GetUser(userid); // 2 means 客户端用户 if (user.UserType == 2) { response.IsSuccess = false; response.Message = "终端用户没有权限修改密码。"; return response; } ub.ChangePassword(userid, request.OldPassword, request.NewPassword,true); response.IsSuccess = true; } catch (Exception ex) { response.IsSuccess = false; response.Message = ex.Message; } return response; }