From 798802daeaa1005cbc1f4c8fc9cf50457bbffb74 Mon Sep 17 00:00:00 2001 From: yuanye <418471657@qq.com> Date: Wed, 13 Nov 2024 14:11:09 +0800 Subject: [PATCH] /1 --- .../user/controller/SecUserController.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/user/src/main/java/com/user/controller/SecUserController.java b/user/src/main/java/com/user/controller/SecUserController.java index 4157c7b..42229ab 100644 --- a/user/src/main/java/com/user/controller/SecUserController.java +++ b/user/src/main/java/com/user/controller/SecUserController.java @@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -107,5 +108,46 @@ public class SecUserController { } + @RequestMapping(value="/sendUserPass",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "修改用户密码") + public ResponseData sendUserPass(@RequestBody String reqBody , HttpServletRequest request) throws Exception{ + try { + + JSONObject jsonObject = JSONObject.parseObject(reqBody); + SecUserSessionObject session = userCenter.getSessionModel(SecUserSessionObject.class); + + Long userId = session.getAccount().getId(); //用户Id + String oldPassword = jsonObject.getString("oldPassword"); //旧密码 + String password = jsonObject.getString("newPassword"); //密码 + + if(userId == null || StringUtils.isBlank(oldPassword) || StringUtils.isBlank(password)) { + log.error("BaseMemberController --> sendUserPass() error!","参数错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + //查询用户 + SecUser secUser = secUserService.getDetail(userId); + if(secUser == null){ + log.error("BaseMemberController --> sendUserPass() error!",""); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户不存在"); + } + if(!secUser.getPassword().equals(MD5Util.encode(oldPassword.getBytes()))) { + log.error("BaseMemberController --> sendUserPass() error!","旧密码不一致"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "旧密码不一致"); + } + secUser.setPassword(MD5Util.encode(password.getBytes())); + //修改 + secUserService.editUser(secUser); + userCenter.remove(request); + return ResponseMsgUtil.success("修改密码成功"); + + } catch (Exception e) { + log.error("getUserByTelephone",e); + return ResponseMsgUtil.exception(e); + } + } + + }