@Test @Ignore public void saveMyAccount() { }
@RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("isAuthenticated()") public String saveMyAccount(@ModelAttribute @Valid AccountForm form, BindingResult bindingResult, Model model, Authentication authentication) throws IOException { if (StringUtils.isNotBlank(form.getNewPassword1()) || StringUtils.isNotBlank(form.getNewPassword2())) { User user = userStore.getUser(authentication.getName()); if (StringUtils.isBlank(form.getPassword())) { bindingResult.rejectValue("password", "user.password.blank"); } else if (!passwordEncoder.matches(form.getPassword(), user.getPassword())) { bindingResult.rejectValue("password", "user.password.wrong"); } if (!StringUtils.equals(form.getNewPassword1(), form.getNewPassword2())) { bindingResult.rejectValue("newPassword1", "user.password.passwordsNotEqual"); } if (!bindingResult.hasErrors()) { String encodedPassword = passwordEncoder.encode(form.getNewPassword1()); User newUser = new User(user.getLoginName(), encodedPassword, user.getEmail(), user.isDisabled()); for (OpenId openId : user.getOpenIds()) { newUser.addOpenId(openId); } userStore.saveUser(newUser, user); } } if (!bindingResult.hasErrors()) { model.addAttribute("messageKey", "dataSaved"); } return "/account/index"; }
AccountController { @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("isAuthenticated()") public String saveMyAccount(@ModelAttribute @Valid AccountForm form, BindingResult bindingResult, Model model, Authentication authentication) throws IOException { if (StringUtils.isNotBlank(form.getNewPassword1()) || StringUtils.isNotBlank(form.getNewPassword2())) { User user = userStore.getUser(authentication.getName()); if (StringUtils.isBlank(form.getPassword())) { bindingResult.rejectValue("password", "user.password.blank"); } else if (!passwordEncoder.matches(form.getPassword(), user.getPassword())) { bindingResult.rejectValue("password", "user.password.wrong"); } if (!StringUtils.equals(form.getNewPassword1(), form.getNewPassword2())) { bindingResult.rejectValue("newPassword1", "user.password.passwordsNotEqual"); } if (!bindingResult.hasErrors()) { String encodedPassword = passwordEncoder.encode(form.getNewPassword1()); User newUser = new User(user.getLoginName(), encodedPassword, user.getEmail(), user.isDisabled()); for (OpenId openId : user.getOpenIds()) { newUser.addOpenId(openId); } userStore.saveUser(newUser, user); } } if (!bindingResult.hasErrors()) { model.addAttribute("messageKey", "dataSaved"); } return "/account/index"; } }
AccountController { @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("isAuthenticated()") public String saveMyAccount(@ModelAttribute @Valid AccountForm form, BindingResult bindingResult, Model model, Authentication authentication) throws IOException { if (StringUtils.isNotBlank(form.getNewPassword1()) || StringUtils.isNotBlank(form.getNewPassword2())) { User user = userStore.getUser(authentication.getName()); if (StringUtils.isBlank(form.getPassword())) { bindingResult.rejectValue("password", "user.password.blank"); } else if (!passwordEncoder.matches(form.getPassword(), user.getPassword())) { bindingResult.rejectValue("password", "user.password.wrong"); } if (!StringUtils.equals(form.getNewPassword1(), form.getNewPassword2())) { bindingResult.rejectValue("newPassword1", "user.password.passwordsNotEqual"); } if (!bindingResult.hasErrors()) { String encodedPassword = passwordEncoder.encode(form.getNewPassword1()); User newUser = new User(user.getLoginName(), encodedPassword, user.getEmail(), user.isDisabled()); for (OpenId openId : user.getOpenIds()) { newUser.addOpenId(openId); } userStore.saveUser(newUser, user); } } if (!bindingResult.hasErrors()) { model.addAttribute("messageKey", "dataSaved"); } return "/account/index"; }  }
AccountController { @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("isAuthenticated()") public String saveMyAccount(@ModelAttribute @Valid AccountForm form, BindingResult bindingResult, Model model, Authentication authentication) throws IOException { if (StringUtils.isNotBlank(form.getNewPassword1()) || StringUtils.isNotBlank(form.getNewPassword2())) { User user = userStore.getUser(authentication.getName()); if (StringUtils.isBlank(form.getPassword())) { bindingResult.rejectValue("password", "user.password.blank"); } else if (!passwordEncoder.matches(form.getPassword(), user.getPassword())) { bindingResult.rejectValue("password", "user.password.wrong"); } if (!StringUtils.equals(form.getNewPassword1(), form.getNewPassword2())) { bindingResult.rejectValue("newPassword1", "user.password.passwordsNotEqual"); } if (!bindingResult.hasErrors()) { String encodedPassword = passwordEncoder.encode(form.getNewPassword1()); User newUser = new User(user.getLoginName(), encodedPassword, user.getEmail(), user.isDisabled()); for (OpenId openId : user.getOpenIds()) { newUser.addOpenId(openId); } userStore.saveUser(newUser, user); } } if (!bindingResult.hasErrors()) { model.addAttribute("messageKey", "dataSaved"); } return "/account/index"; }  @RequestMapping(value="/myAccount", method=RequestMethod.GET) @PreAuthorize("isAuthenticated()") String getMyAccount(Model model); @RequestMapping(value="/openId", method=RequestMethod.GET) @PreAuthorize("isAuthenticated()") String getMyOpenIds(); @RequestMapping(value="/removeOpenId", method=RequestMethod.GET) @PreAuthorize("isAuthenticated()") String removeOpenId(@RequestParam String openId, Authentication authentication); @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("isAuthenticated()") String saveMyAccount(@ModelAttribute @Valid AccountForm form, BindingResult bindingResult, Model model,
			Authentication authentication); @ModelAttribute AccountForm createAccountForm(@RequestParam(required=false) String password,
			@RequestParam(required=false) String newPassword1, @RequestParam(required=false) String newPassword2); }
AccountController { @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("isAuthenticated()") public String saveMyAccount(@ModelAttribute @Valid AccountForm form, BindingResult bindingResult, Model model, Authentication authentication) throws IOException { if (StringUtils.isNotBlank(form.getNewPassword1()) || StringUtils.isNotBlank(form.getNewPassword2())) { User user = userStore.getUser(authentication.getName()); if (StringUtils.isBlank(form.getPassword())) { bindingResult.rejectValue("password", "user.password.blank"); } else if (!passwordEncoder.matches(form.getPassword(), user.getPassword())) { bindingResult.rejectValue("password", "user.password.wrong"); } if (!StringUtils.equals(form.getNewPassword1(), form.getNewPassword2())) { bindingResult.rejectValue("newPassword1", "user.password.passwordsNotEqual"); } if (!bindingResult.hasErrors()) { String encodedPassword = passwordEncoder.encode(form.getNewPassword1()); User newUser = new User(user.getLoginName(), encodedPassword, user.getEmail(), user.isDisabled()); for (OpenId openId : user.getOpenIds()) { newUser.addOpenId(openId); } userStore.saveUser(newUser, user); } } if (!bindingResult.hasErrors()) { model.addAttribute("messageKey", "dataSaved"); } return "/account/index"; }  @RequestMapping(value="/myAccount", method=RequestMethod.GET) @PreAuthorize("isAuthenticated()") String getMyAccount(Model model); @RequestMapping(value="/openId", method=RequestMethod.GET) @PreAuthorize("isAuthenticated()") String getMyOpenIds(); @RequestMapping(value="/removeOpenId", method=RequestMethod.GET) @PreAuthorize("isAuthenticated()") String removeOpenId(@RequestParam String openId, Authentication authentication); @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("isAuthenticated()") String saveMyAccount(@ModelAttribute @Valid AccountForm form, BindingResult bindingResult, Model model,
			Authentication authentication); @ModelAttribute AccountForm createAccountForm(@RequestParam(required=false) String password,
			@RequestParam(required=false) String newPassword1, @RequestParam(required=false) String newPassword2);  }