袁野 2 weeks ago
parent c123f99bd2
commit 798802daea
  1. 42
      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.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; 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);
}
}
} }

Loading…
Cancel
Save