@RequestMapping(value = "{id}", method = RequestMethod.PUT) public String update(@LoginUser SocialUser loginUser, @PathVariable Long id, UserForm userForm) throws Exception { SocialUser socialUser = userService.findById(id); if (!loginUser.isSameUser(socialUser)) { throw new IllegalArgumentException("You cann't change another user!"); } userService.updateSlippUser(loginUser, userForm.getEmail(), userForm.getUserId()); return "redirect:/users/logout"; }
@RequestMapping("{id}/changepassword") public String changePasswordForm( @LoginUser SocialUser loginUser, @PathVariable Long id, Model model) throws Exception { SocialUser socialUser = userService.findById(id); if (!loginUser.isSameUser(socialUser)) { throw new IllegalArgumentException("You cann't change another user!"); } model.addAttribute("socialUser", socialUser); model.addAttribute("password", new PasswordDto(id)); return "users/changepassword"; }
@RequestMapping("{id}/form") public String updateForm(@LoginUser SocialUser loginUser, @PathVariable Long id, Model model) throws Exception { SocialUser socialUser = userService.findById(id); if (!loginUser.isSameUser(socialUser)) { throw new IllegalArgumentException("You cann't change another user!"); } model.addAttribute("user", new UserForm(socialUser.getUserId(), socialUser.getEmail())); model.addAttribute("socialUser", socialUser); return "users/form"; }
@RequestMapping(value = "{id}/changepassword", method = RequestMethod.POST) public String changePassword( @LoginUser SocialUser loginUser, @PathVariable Long id, PasswordDto password, Model model) throws Exception { SocialUser socialUser = userService.findById(id); if (!loginUser.isSameUser(socialUser)) { throw new IllegalArgumentException("You cann't change another user!"); } try { userService.changePassword(loginUser, password); return "redirect:/users/logout"; } catch (BadCredentialsException e) { model.addAttribute("errorMessage", e.getMessage()); model.addAttribute("socialUser", socialUser); model.addAttribute("password", new PasswordDto(id)); return "users/changepassword"; } }