public IActionResult UpdatePassword(UpdatePasswordParam param) { var resultMsg = new ResponseModel(ResponseCode.Error, "修改失败", false); try { if (string.IsNullOrEmpty(param.old_password) || string.IsNullOrEmpty(param.new_password)) { resultMsg.msg = "参数验证不通过"; return(Json(resultMsg)); } var doctor = this.Query <SystemUser>() .Where("id", param.userid) .Where("登录密码", Strings.StrToMD5(param.old_password)).GetModel(); if (doctor == null) { resultMsg.msg = "用户信息不存在!"; return(Json(resultMsg)); } if (doctor.密码 != Strings.StrToMD5(param.old_password)) { resultMsg.msg = "原密码输入错误!"; return(Json(resultMsg)); } //请求参数转换成业务逻辑需要的请求参数对象 var entity = new SystemUser() { id = param.userid, 密码 = Strings.StrToMD5(param.new_password),//加密 }; var count = this.Update <SystemUser>(entity) .Columns("密码") .Where("id", entity.id) .Execute(); if (count > 0)//判断不为空 { resultMsg.data = true; resultMsg.code = (int)ResponseCode.Success; resultMsg.msg = "修改成功"; } } catch (Exception ex) { LogError("修改密码", ex); resultMsg.msg = "修改异常"; } return(Json(resultMsg)); }
/// <summary> /// 更新密码 /// </summary> /// <param name="newPassword">新密码</param> /// <param name="oldPassword">旧密码</param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task<User> UpdatePassword( string newPassword, string oldPassword, CancellationToken cancellationToken = default) { await CheckLoggedIn(); var param = new UpdatePasswordParam() { NewPassword = Encrypt(newPassword), OldPassword = Encrypt(oldPassword), }; var res = await Request<UpdatePasswordResponse>(param.CreateRequest(), cancellationToken); CurrentUser = res.Result; return res.Result; }
public HttpResponseMessage UpdatePassword([FromBody] UpdatePasswordParam Param) { try { AccountProvider _Provider = new AccountProvider(); var result = _Provider.UpdatePassword(Param); return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { LogFactory _LogFactory = new LogFactory(this.GetType()); _LogFactory.CreateLog(LogType.Error, "修改密码", "UpdatePassword", ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }