/** * Anonymous checkout process. * * <p>Creates a new guest customer and updates the session cart with this user. The session user * will be anonymous and it's never updated with this guest user. * * <p>If email is required, grab the email from the form and set it as uid with "guid|email" * format. * * @throws de.hybris.platform.cms2.exceptions.CMSItemNotFoundException */ protected String processAnonymousCheckoutUserRequest( final GuestForm form, final BindingResult bindingResult, final Model model, final HttpServletRequest request, final HttpServletResponse response) throws CMSItemNotFoundException { try { if (bindingResult.hasErrors()) { model.addAttribute(form); model.addAttribute(new LoginForm()); model.addAttribute(new RegisterForm()); GlobalMessages.addErrorMessage(model, "form.global.error"); return handleRegistrationError(model); } getCustomerFacade() .createGuestUserForAnonymousCheckout( form.getEmail(), getMessageSource() .getMessage("text.guest.customer", null, getI18nService().getCurrentLocale())); getGuidCookieStrategy().setCookie(request, response); getSessionService().setAttribute(WebConstants.ANONYMOUS_CHECKOUT, Boolean.TRUE); } catch (final DuplicateUidException e) { LOG.warn("guest registration failed: " + e); GlobalMessages.addErrorMessage(model, "form.global.error"); return handleRegistrationError(model); } return REDIRECT_PREFIX + getSuccessRedirect(request, response); }
/** * This method takes data from the registration form and create a new customer account and * attempts to log in using the credentials of this new user. * * @param referer * @param form * @param bindingResult * @param model * @param request * @param response * @return true if there are no binding errors or the account does not already exists. * @throws CMSItemNotFoundException */ protected String processRegisterUserRequest( final String referer, final RegisterForm form, final BindingResult bindingResult, final Model model, final HttpServletRequest request, final HttpServletResponse response, final RedirectAttributes redirectModel) throws CMSItemNotFoundException { if (bindingResult.hasErrors()) { model.addAttribute(form); model.addAttribute(new LoginForm()); model.addAttribute(new GuestForm()); GlobalMessages.addErrorMessage(model, "form.global.error"); return handleRegistrationError(model); } final RegisterData data = new RegisterData(); data.setFirstName(form.getFirstName()); data.setLastName(form.getLastName()); data.setLogin(form.getEmail()); data.setPassword(form.getPwd()); data.setTitleCode(form.getTitleCode()); try { getCustomerFacade().register(data); getAutoLoginStrategy().login(form.getEmail().toLowerCase(), form.getPwd(), request, response); GlobalMessages.addFlashMessage( redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "registration.confirmation.message.title"); } catch (final DuplicateUidException e) { LOG.warn("registration failed: " + e); model.addAttribute(form); model.addAttribute(new LoginForm()); model.addAttribute(new GuestForm()); bindingResult.rejectValue("email", "registration.error.account.exists.title"); GlobalMessages.addErrorMessage(model, "form.global.error"); return handleRegistrationError(model); } return REDIRECT_PREFIX + getSuccessRedirect(request, response); }