@Test public void updatePassword() throws Exception { GroupDO group = GroupDO.builder().name("少林足球").info("致敬周星星").build(); groupMapper.insert(group); RegisterDTO dto = new RegisterDTO(); dto.setGroupIds(Arrays.asList(group.getId())); dto.setEmail(email); dto.setConfirmPassword(password); dto.setPassword(password); dto.setUsername(username); userService.createUser(dto); UserDO user = userService.getUserByUsername(username); LocalUser.setLocalUser(user); ChangePasswordDTO dto1 = new ChangePasswordDTO(); dto1.setOldPassword(password); dto1.setNewPassword("147258"); dto1.setConfirmPassword("147258"); ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); String content = mapper.writeValueAsString(dto1); mvc.perform(MockMvcRequestBuilders.put("/cms/user/change_password") .contentType(MediaType.APPLICATION_JSON).content(content)) .andDo(print()) .andExpect(status().isOk()) .andExpect(MockMvcResultMatchers. jsonPath("$.message").value("密码修改成功")); }
@PutMapping("/change_password") @LoginRequired public UnifyResponseVO updatePassword(@RequestBody @Validated ChangePasswordDTO validator) { userService.changeUserPassword(validator); return ResponseUtil.generateUnifyResponse(2); }
UserController { @PutMapping("/change_password") @LoginRequired public UnifyResponseVO updatePassword(@RequestBody @Validated ChangePasswordDTO validator) { userService.changeUserPassword(validator); return ResponseUtil.generateUnifyResponse(2); } }
UserController { @PutMapping("/change_password") @LoginRequired public UnifyResponseVO updatePassword(@RequestBody @Validated ChangePasswordDTO validator) { userService.changeUserPassword(validator); return ResponseUtil.generateUnifyResponse(2); }  }
UserController { @PutMapping("/change_password") @LoginRequired public UnifyResponseVO updatePassword(@RequestBody @Validated ChangePasswordDTO validator) { userService.changeUserPassword(validator); return ResponseUtil.generateUnifyResponse(2); }  @PostMapping("/register") @AdminRequired UnifyResponseVO<String> register(@RequestBody @Validated RegisterDTO validator); @PostMapping("/login") Tokens login(@RequestBody @Validated LoginDTO validator); @PutMapping @LoginRequired UnifyResponseVO update(@RequestBody @Validated UpdateInfoDTO validator); @PutMapping("/change_password") @LoginRequired UnifyResponseVO updatePassword(@RequestBody @Validated ChangePasswordDTO validator); @GetMapping("/refresh") @RefreshRequired Tokens refreshToken(); @GetMapping("/permissions") @LoginRequired @RouteMeta(permission = "查询自己拥有的权限", module = "用户", mount = true) UserPermissionsVO getPermissions(); @LoginRequired @RouteMeta(permission = "查询自己信息", module = "用户", mount = true) @GetMapping("/information") UserInfoVO getInformation(); }
UserController { @PutMapping("/change_password") @LoginRequired public UnifyResponseVO updatePassword(@RequestBody @Validated ChangePasswordDTO validator) { userService.changeUserPassword(validator); return ResponseUtil.generateUnifyResponse(2); }  @PostMapping("/register") @AdminRequired UnifyResponseVO<String> register(@RequestBody @Validated RegisterDTO validator); @PostMapping("/login") Tokens login(@RequestBody @Validated LoginDTO validator); @PutMapping @LoginRequired UnifyResponseVO update(@RequestBody @Validated UpdateInfoDTO validator); @PutMapping("/change_password") @LoginRequired UnifyResponseVO updatePassword(@RequestBody @Validated ChangePasswordDTO validator); @GetMapping("/refresh") @RefreshRequired Tokens refreshToken(); @GetMapping("/permissions") @LoginRequired @RouteMeta(permission = "查询自己拥有的权限", module = "用户", mount = true) UserPermissionsVO getPermissions(); @LoginRequired @RouteMeta(permission = "查询自己信息", module = "用户", mount = true) @GetMapping("/information") UserInfoVO getInformation();  }