I have a controller that is supposed to redirect to another endpoint after processing but it only works when I set the active profile to dev
. When the profile is not dev
, the controller returns to the login page instead of redirecting to the profile endpoint.
This is my controller
public String completeSignUp(
@RequestParam final String token, @RequestParam final String userId,
Model model, RedirectAttributes redirectAttributes, HttpServletRequest httpServletRequest) {
LOG.debug("About to complete the sign-up process with token: {} and userId {}", token, userId);
try {
InputValidationUtility.validateInputs(getClass(), token, userId, model);
UserDto userDto = updateUserAndSendConfirmationEmail(token, userId, model, httpServletRequest);
if (Objects.isNull(userDto) || model.containsAttribute(SignUpControllerConstant.SIGN_UP_ERROR)) {
model.addAttribute(UserConstant.USER_MODEL_KEY, new UserRequestModel());
return SignUpControllerConstant.SIGN_UP_VIEW_NAME;
}
// automatically authenticate the userDto since there will be a redirection to profile page
UserUtility.authenticateUser(userService, userDto.getUsername());
model.addAttribute(SignUpControllerConstant.SIGN_UP_SUCCESS_KEY, true);
model.addAttribute(USER_REQUEST_MODEL_KEY_NAME, new UserRequestModel());
redirectAttributes.addFlashAttribute(ProfileControllerConstant.NEW_PROFILE, true);
LOG.debug("Redirecting to profile page...");
return "redirect:/profile";
} catch (Exception e) {
LOG.error(SignUpControllerConstant.ERROR_CREATING_USER, e);
model.addAttribute(SignUpControllerConstant.ERROR, SignUpControllerConstant.ERROR_CREATING_USER);
return SignUpControllerConstant.SIGN_UP_VIEW_NAME;
}
}
The profile page requires authentication and has the endpoint /profile
.
This code works in "dev" profile
Aucun commentaire:
Enregistrer un commentaire