final RequestData requestData = requestUtil.getRequestData(request);
final Market currentMarket = requestData.getMarket();
final MarketArea currentMarketArea = requestData.getMarketArea();
// SANITY CHECK: Customer logged
final Customer currentCustomer = requestData.getCustomer();
if(currentCustomer != null){
final String url = urlService.generateUrl(FoUrls.PERSONAL_DETAILS,requestUtil.getRequestData(request));
return new ModelAndView(new RedirectView(url));
}
// "customer.create.account";
if (result.hasErrors()) {
return displayCustomerCreateAccount(request, model, createAccountForm);
}
final String email = createAccountForm.getEmail();
final Customer customer = customerService.getCustomerByLoginOrEmail(email);
if(customer != null){
final String forgottenPasswordUrl = urlService.generateUrl(FoUrls.FORGOTTEN_PASSWORD, requestUtil.getRequestData(request));
final Object[] objects = {forgottenPasswordUrl};
result.rejectValue("email", "fo.customer.error_form_create_account_account_already_exist", objects,"This email customer account already exist! Go on this <a href=\"forgotten-password.html\" alt=\"\">page</a> to get a new password.");
return displayCustomerCreateAccount(request, model, createAccountForm);
}
// Save the new customer
final Customer newCustomer = webManagementService.buildAndSaveNewCustomer(requestData, currentMarket, currentMarketArea, createAccountForm);
// Save the email confirmation
webManagementService.buildAndSaveCustomerNewAccountMail(requestData, createAccountForm);
// Login the new customer