首页 > 解决方案 > 如何使用 spring boot 和 postman 测试重置密码请求?

问题描述

我目前正在为用户重置密码,但我在测试该方法时遇到了问题。这是下面的代码:

    @PostMapping("/user/resetPassword")
public GenericResponse resetPassword(HttpServletRequest request, @RequestBody String userEmail) {
    System.out.println("Here we are in the method of the reset *********");
    User user = userRepository.findByEmail1(userEmail);
    System.out.println ( user.getId());
    System.out.println("This is my user"+user);
    if (user == null) {
        throw new UserNotFoundException();
    }
    String token = UUID.randomUUID().toString();
    userService.createPasswordResetTokenForUser(user, token);
    mailSender.send(constructResetTokenEmail(getAppUrl(request), request.getLocale(), token, user));
    return new GenericResponse(messages.getMessage("message.resetPasswordEmail", null, request.getLocale()));
}

问题出在 findByEmail 中,它没有从我在 Postman 有效负载的 JSON 中插入的电子邮件中返回用户:

User findByEmail(String email);

执行的结果是 UserNotFoundException。

标签: spring-bootjpa

解决方案


推荐阅读