private Account createAccount(SignupForm form, BindingResult formBinding) { try { Account account = new Account( form.getUsername(), form.getPassword(), form.getFirstName(), form.getLastName()); accountRepository.createAccount(account); return account; } catch (UsernameAlreadyInUseException e) { formBinding.rejectValue("username", "user.duplicateUsername", "already in use"); return null; } }
@RequestMapping(value = "signup", method = RequestMethod.POST) public String signup( @Valid @ModelAttribute SignupForm signupForm, Errors errors, RedirectAttributes ra) { if (errors.hasErrors()) { return null; } Account account = accountRepository.save(signupForm.createAccount()); userService.signin(account); MessageHelper.addSuccessAttribute(ra, "Congratulations! You have successfully signed up."); return "redirect:/"; }
@RequestMapping(value = "/signup", method = RequestMethod.GET) public SignupForm signupForm(WebRequest request) { Connection<?> connection = ProviderSignInUtils.getConnection(request); if (connection != null) { request.setAttribute( "message", new Message( MessageType.INFO, "Your " + StringUtils.capitalize(connection.getKey().getProviderId()) + " account is not associated with a Spring Social Popup account. If you're new, please sign up."), WebRequest.SCOPE_REQUEST); return SignupForm.fromProviderUser(connection.fetchUserProfile()); } else { return new SignupForm(); } }