@RequestMapping(method = RequestMethod.GET)
  public String get(
      final Model model, final HttpServletRequest request, final HttpServletResponse response)
      throws CMSItemNotFoundException {
    // Check for CMS Page where label or id is like /page
    final ContentPageModel pageForRequest = getContentPageForRequest(request);
    if (pageForRequest != null) {
      storeCmsPageInModel(model, pageForRequest);
      setUpMetaDataForContentPage(model, pageForRequest);
      model.addAttribute(
          WebConstants.BREADCRUMBS_KEY,
          contentPageBreadcrumbBuilder.getBreadcrumbs(pageForRequest));
      return getViewForPage(pageForRequest);
    }

    // No page found - display the notFound page with error from controller
    storeCmsPageInModel(model, getContentPageForLabelOrId(ERROR_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ERROR_CMS_PAGE));

    model.addAttribute(
        WebConstants.MODEL_KEY_ADDITIONAL_BREADCRUMB,
        resourceBreadcrumbBuilder.getBreadcrumbs("breadcrumb.not.found"));
    GlobalMessages.addErrorMessage(model, "system.error.page.not.found");

    response.setStatus(HttpServletResponse.SC_NOT_FOUND);

    return ControllerConstants.Views.Pages.Error.ErrorNotFoundPage;
  }
コード例 #2
0
  @RequestMapping(value = "/request/external", method = RequestMethod.POST)
  public String externalPasswordRequest(
      @Valid final ForgottenPwdForm form,
      final BindingResult bindingResult,
      final Model model,
      final RedirectAttributes redirectModel)
      throws CMSItemNotFoundException {
    storeCmsPageInModel(model, getContentPageForLabelOrId(null));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(null));
    model.addAttribute(
        WebConstants.BREADCRUMBS_KEY,
        resourceBreadcrumbBuilder.getBreadcrumbs("forgottenPwd.title"));

    if (bindingResult.hasErrors()) {
      return ControllerConstants.Views.Pages.Password.PasswordResetRequest;
    } else {
      try {
        customerFacade.forgottenPassword(form.getEmail());
        GlobalMessages.addFlashMessage(
            redirectModel,
            GlobalMessages.CONF_MESSAGES_HOLDER,
            "account.confirmation.forgotten.password.link.sent");
      } catch (final UnknownIdentifierException unknownIdentifierException) {
        LOG.warn("Email: " + form.getEmail() + " does not exist in the database.");
      }
      return REDIRECT_PWD_REQ_CONF;
    }
  }
  @RequestMapping(value = "/add-address", method = RequestMethod.GET)
  @RequireHardLogIn
  public String addAddress(final Model model) throws CMSItemNotFoundException {
    model.addAttribute("countryData", checkoutFacade.getDeliveryCountries());
    model.addAttribute("titleData", userFacade.getTitles());
    final AddressForm addressForm = getPreparedAddressForm();
    model.addAttribute("addressForm", addressForm);
    model.addAttribute("addressBookEmpty", Boolean.valueOf(userFacade.isAddressBookEmpty()));
    model.addAttribute("isDefaultAddress", Boolean.FALSE);
    storeCmsPageInModel(model, getContentPageForLabelOrId(ADD_EDIT_ADDRESS_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ADD_EDIT_ADDRESS_CMS_PAGE));

    final List<Breadcrumb> breadcrumbs = accountBreadcrumbBuilder.getBreadcrumbs(null);
    breadcrumbs.add(
        new Breadcrumb(
            "/my-account/address-book",
            getMessageSource()
                .getMessage("text.account.addressBook", null, getI18nService().getCurrentLocale()),
            null));
    breadcrumbs.add(
        new Breadcrumb(
            "#",
            getMessageSource()
                .getMessage(
                    "text.account.addressBook.addEditAddress",
                    null,
                    getI18nService().getCurrentLocale()),
            null));
    model.addAttribute("breadcrumbs", breadcrumbs);
    model.addAttribute("metaRobots", "noindex,nofollow");
    return getViewForPage(model);
  }
 protected String errorUpdatingEmail(final Model model) throws CMSItemNotFoundException {
   GlobalMessages.addErrorMessage(model, "form.global.error");
   storeCmsPageInModel(model, getContentPageForLabelOrId(UPDATE_EMAIL_CMS_PAGE));
   setUpMetaDataForContentPage(model, getContentPageForLabelOrId(UPDATE_EMAIL_CMS_PAGE));
   model.addAttribute(
       "breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile"));
   return getViewForPage(model);
 }
 @RequestMapping(method = RequestMethod.GET)
 @RequireHardLogIn
 public String account(final Model model) throws CMSItemNotFoundException {
   storeCmsPageInModel(model, getContentPageForLabelOrId(ACCOUNT_CMS_PAGE));
   setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ACCOUNT_CMS_PAGE));
   model.addAttribute("breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs(null));
   model.addAttribute("metaRobots", "noindex,nofollow");
   return getViewForPage(model);
 }
コード例 #6
0
 @RequestMapping(value = "/request/external/conf", method = RequestMethod.GET)
 public String getExternalPasswordRequestConf(final Model model) throws CMSItemNotFoundException {
   storeCmsPageInModel(model, getContentPageForLabelOrId(null));
   setUpMetaDataForContentPage(model, getContentPageForLabelOrId(null));
   model.addAttribute(
       WebConstants.BREADCRUMBS_KEY,
       resourceBreadcrumbBuilder.getBreadcrumbs("forgottenPwd.title"));
   return ControllerConstants.Views.Pages.Password.PasswordResetRequestConfirmation;
 }
 @RequestMapping(value = "/payment-details", method = RequestMethod.GET)
 @RequireHardLogIn
 public String paymentDetails(final Model model) throws CMSItemNotFoundException {
   model.addAttribute("customerData", customerFacade.getCurrentCustomer());
   model.addAttribute("paymentInfoData", userFacade.getCCPaymentInfos(true));
   storeCmsPageInModel(model, getContentPageForLabelOrId(PAYMENT_DETAILS_CMS_PAGE));
   setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ADD_EDIT_ADDRESS_CMS_PAGE));
   model.addAttribute(
       "breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.paymentDetails"));
   model.addAttribute("metaRobots", "noindex,nofollow");
   return getViewForPage(model);
 }
  @RequestMapping(value = "/address-book", method = RequestMethod.GET)
  @RequireHardLogIn
  public String getAddressBook(final Model model) throws CMSItemNotFoundException {
    model.addAttribute("addressData", userFacade.getAddressBook());

    storeCmsPageInModel(model, getContentPageForLabelOrId(ADDRESS_BOOK_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ADDRESS_BOOK_CMS_PAGE));
    model.addAttribute(
        "breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.addressBook"));
    model.addAttribute("metaRobots", "noindex,nofollow");
    return getViewForPage(model);
  }
  @RequestMapping(value = "/update-password", method = RequestMethod.POST)
  @RequireHardLogIn
  public String updatePassword(
      final UpdatePasswordForm updatePasswordForm,
      final BindingResult bindingResult,
      final Model model,
      final RedirectAttributes redirectAttributes)
      throws CMSItemNotFoundException {
    getPasswordValidator().validate(updatePasswordForm, bindingResult);
    if (!bindingResult.hasErrors()) {
      if (updatePasswordForm.getNewPassword().equals(updatePasswordForm.getCheckNewPassword())) {
        try {
          customerFacade.changePassword(
              updatePasswordForm.getCurrentPassword(), updatePasswordForm.getNewPassword());
        } catch (final PasswordMismatchException localException) {
          bindingResult.rejectValue(
              "currentPassword",
              "profile.currentPassword.invalid",
              new Object[] {},
              "profile.currentPassword.invalid");
        }
      } else {
        bindingResult.rejectValue(
            "checkNewPassword",
            "validation.checkPwd.equals",
            new Object[] {},
            "validation.checkPwd.equals");
      }
    }

    if (bindingResult.hasErrors()) {
      GlobalMessages.addErrorMessage(model, "form.global.error");
      storeCmsPageInModel(model, getContentPageForLabelOrId(UPDATE_PASSWORD_CMS_PAGE));
      setUpMetaDataForContentPage(model, getContentPageForLabelOrId(UPDATE_PASSWORD_CMS_PAGE));

      model.addAttribute(
          "breadcrumbs",
          accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile.updatePasswordForm"));
      return getViewForPage(model);
    } else {
      GlobalMessages.addFlashMessage(
          redirectAttributes,
          GlobalMessages.CONF_MESSAGES_HOLDER,
          "text.account.confirmation.password.updated",
          null);
      return REDIRECT_TO_PROFILE_PAGE;
    }
  }
  @RequestMapping(value = "/update-password", method = RequestMethod.GET)
  @RequireHardLogIn
  public String updatePassword(final Model model) throws CMSItemNotFoundException {
    final UpdatePasswordForm updatePasswordForm = new UpdatePasswordForm();

    model.addAttribute("updatePasswordForm", updatePasswordForm);

    storeCmsPageInModel(model, getContentPageForLabelOrId(UPDATE_PASSWORD_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(UPDATE_PASSWORD_CMS_PAGE));

    model.addAttribute(
        "breadcrumbs",
        accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile.updatePasswordForm"));
    model.addAttribute("metaRobots", "noindex,nofollow");
    return getViewForPage(model);
  }
コード例 #11
0
 @RequestMapping(value = "/change", method = RequestMethod.GET)
 public String getChangePassword(
     @RequestParam(required = false) final String token, final Model model)
     throws CMSItemNotFoundException {
   if (StringUtils.isBlank(token)) {
     return REDIRECT_HOME;
   }
   final UpdatePwdForm form = new UpdatePwdForm();
   form.setToken(token);
   model.addAttribute(form);
   storeCmsPageInModel(model, getContentPageForLabelOrId(UPDATE_PWD_CMS_PAGE));
   setUpMetaDataForContentPage(model, getContentPageForLabelOrId(UPDATE_PWD_CMS_PAGE));
   model.addAttribute(
       WebConstants.BREADCRUMBS_KEY, resourceBreadcrumbBuilder.getBreadcrumbs("updatePwd.title"));
   return ControllerConstants.Views.Pages.Password.PasswordResetChangePage;
 }
  @RequestMapping(value = "/update-email", method = RequestMethod.GET)
  @RequireHardLogIn
  public String editEmail(final Model model) throws CMSItemNotFoundException {
    final CustomerData customerData = customerFacade.getCurrentCustomer();
    final UpdateEmailForm updateEmailForm = new UpdateEmailForm();

    updateEmailForm.setEmail(customerData.getDisplayUid());

    model.addAttribute("updateEmailForm", updateEmailForm);

    storeCmsPageInModel(model, getContentPageForLabelOrId(UPDATE_EMAIL_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(UPDATE_EMAIL_CMS_PAGE));
    model.addAttribute(
        "breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile"));
    model.addAttribute("metaRobots", "noindex,nofollow");
    return getViewForPage(model);
  }
  @RequestMapping(value = "/update-profile", method = RequestMethod.POST)
  @RequireHardLogIn
  public String updateProfile(
      final UpdateProfileForm updateProfileForm,
      final BindingResult bindingResult,
      final Model model,
      final RedirectAttributes redirectAttributes)
      throws CMSItemNotFoundException {
    getProfileValidator().validate(updateProfileForm, bindingResult);

    String returnAction = ControllerConstants.Views.Pages.Account.AccountProfileEditPage;
    final CustomerData currentCustomerData = customerFacade.getCurrentCustomer();
    final CustomerData customerData = new CustomerData();
    customerData.setTitleCode(updateProfileForm.getTitleCode());
    customerData.setFirstName(updateProfileForm.getFirstName());
    customerData.setLastName(updateProfileForm.getLastName());
    customerData.setUid(currentCustomerData.getUid());
    customerData.setDisplayUid(currentCustomerData.getDisplayUid());

    model.addAttribute("titleData", userFacade.getTitles());

    if (bindingResult.hasErrors()) {
      GlobalMessages.addErrorMessage(model, "form.global.error");
    } else {
      try {
        customerFacade.updateProfile(customerData);
        GlobalMessages.addFlashMessage(
            redirectAttributes,
            GlobalMessages.CONF_MESSAGES_HOLDER,
            "text.account.profile.confirmationUpdated",
            null);
        returnAction = REDIRECT_TO_PROFILE_PAGE;
      } catch (final DuplicateUidException e) {
        bindingResult.rejectValue("email", "registration.error.account.exists.title");
        GlobalMessages.addErrorMessage(model, "form.global.error");
      }
    }

    storeCmsPageInModel(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE));
    model.addAttribute(
        "breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile"));
    return returnAction;
  }
  @RequestMapping(value = "/profile", method = RequestMethod.GET)
  @RequireHardLogIn
  public String profile(final Model model) throws CMSItemNotFoundException {
    final List<TitleData> titles = userFacade.getTitles();

    final CustomerData customerData = customerFacade.getCurrentCustomer();
    if (customerData.getTitleCode() != null) {
      model.addAttribute("title", findTitleForCode(titles, customerData.getTitleCode()));
    }

    model.addAttribute("customerData", customerData);

    storeCmsPageInModel(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE));
    model.addAttribute(
        "breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile"));
    model.addAttribute("metaRobots", "noindex,nofollow");
    return getViewForPage(model);
  }
  @RequestMapping(value = "/orders", method = RequestMethod.GET)
  @RequireHardLogIn
  public String orders(
      @RequestParam(value = "page", defaultValue = "0") final int page,
      @RequestParam(value = "show", defaultValue = "Page") final ShowMode showMode,
      @RequestParam(value = "sort", required = false) final String sortCode,
      final Model model)
      throws CMSItemNotFoundException {
    // Handle paged search results
    final PageableData pageableData = createPageableData(page, 5, sortCode, showMode);
    final SearchPageData<OrderHistoryData> searchPageData =
        orderFacade.getPagedOrderHistoryForStatuses(pageableData);
    populateModel(model, searchPageData, showMode);

    storeCmsPageInModel(model, getContentPageForLabelOrId(ORDER_HISTORY_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ORDER_HISTORY_CMS_PAGE));
    model.addAttribute(
        "breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.orderHistory"));
    model.addAttribute("metaRobots", "noindex,nofollow");
    return getViewForPage(model);
  }
  @RequestMapping(value = "/update-profile", method = RequestMethod.GET)
  @RequireHardLogIn
  public String editProfile(final Model model) throws CMSItemNotFoundException {
    model.addAttribute("titleData", userFacade.getTitles());

    final CustomerData customerData = customerFacade.getCurrentCustomer();
    final UpdateProfileForm updateProfileForm = new UpdateProfileForm();

    updateProfileForm.setTitleCode(customerData.getTitleCode());
    updateProfileForm.setFirstName(customerData.getFirstName());
    updateProfileForm.setLastName(customerData.getLastName());

    model.addAttribute("updateProfileForm", updateProfileForm);

    storeCmsPageInModel(model, getContentPageForLabelOrId(UPDATE_PROFILE_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(UPDATE_PROFILE_CMS_PAGE));

    model.addAttribute(
        "breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile"));
    model.addAttribute("metaRobots", "noindex,nofollow");
    return getViewForPage(model);
  }
  @RequestMapping(value = "/order/" + ORDER_CODE_PATH_VARIABLE_PATTERN, method = RequestMethod.GET)
  @RequireHardLogIn
  public String order(@PathVariable("orderCode") final String orderCode, final Model model)
      throws CMSItemNotFoundException {
    try {
      final OrderData orderDetails = orderFacade.getOrderDetailsForCode(orderCode);
      model.addAttribute("orderData", orderDetails);

      final List<Breadcrumb> breadcrumbs = accountBreadcrumbBuilder.getBreadcrumbs(null);
      breadcrumbs.add(
          new Breadcrumb(
              "/my-account/orders",
              getMessageSource()
                  .getMessage(
                      "text.account.orderHistory", null, getI18nService().getCurrentLocale()),
              null));
      breadcrumbs.add(
          new Breadcrumb(
              "#",
              getMessageSource()
                  .getMessage(
                      "text.account.order.orderBreadcrumb",
                      new Object[] {orderDetails.getCode()},
                      "Order {0}",
                      getI18nService().getCurrentLocale()),
              null));
      model.addAttribute("breadcrumbs", breadcrumbs);

    } catch (final UnknownIdentifierException e) {
      LOG.warn("Attempted to load a order that does not exist or is not visible", e);
      return REDIRECT_MY_ACCOUNT;
    }
    storeCmsPageInModel(model, getContentPageForLabelOrId(ORDER_DETAIL_CMS_PAGE));
    model.addAttribute("metaRobots", "noindex,nofollow");
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ORDER_DETAIL_CMS_PAGE));
    return getViewForPage(model);
  }
  @RequestMapping(
      value = "/edit-address/" + ADDRESS_CODE_PATH_VARIABLE_PATTERN,
      method = RequestMethod.GET)
  @RequireHardLogIn
  public String editAddress(
      @PathVariable("addressCode") final String addressCode, final Model model)
      throws CMSItemNotFoundException {
    final AddressForm addressForm = new AddressForm();
    model.addAttribute("countryData", checkoutFacade.getDeliveryCountries());
    model.addAttribute("titleData", userFacade.getTitles());
    model.addAttribute("addressForm", addressForm);
    model.addAttribute("addressBookEmpty", Boolean.valueOf(userFacade.isAddressBookEmpty()));

    for (final AddressData addressData : userFacade.getAddressBook()) {
      if (addressData.getId() != null && addressData.getId().equals(addressCode)) {
        model.addAttribute(
            "regions",
            getI18NFacade().getRegionsForCountryIso(addressData.getCountry().getIsocode()));
        model.addAttribute("country", addressData.getCountry().getIsocode());
        model.addAttribute("addressData", addressData);
        addressForm.setAddressId(addressData.getId());
        addressForm.setTitleCode(addressData.getTitleCode());
        addressForm.setFirstName(addressData.getFirstName());
        addressForm.setLastName(addressData.getLastName());
        addressForm.setLine1(addressData.getLine1());
        addressForm.setLine2(addressData.getLine2());
        addressForm.setTownCity(addressData.getTown());
        addressForm.setPostcode(addressData.getPostalCode());
        addressForm.setCountryIso(addressData.getCountry().getIsocode());
        if (addressData.getRegion() != null
            && !StringUtils.isEmpty(addressData.getRegion().getIsocode())) {
          addressForm.setRegionIso(addressData.getRegion().getIsocode());
        }

        if (isDefaultAddress(addressData.getId())) {
          addressForm.setDefaultAddress(Boolean.TRUE);
          model.addAttribute("isDefaultAddress", Boolean.TRUE);
        } else {
          addressForm.setDefaultAddress(Boolean.FALSE);
          model.addAttribute("isDefaultAddress", Boolean.FALSE);
        }
        break;
      }
    }

    storeCmsPageInModel(model, getContentPageForLabelOrId(ADD_EDIT_ADDRESS_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ADD_EDIT_ADDRESS_CMS_PAGE));

    final List<Breadcrumb> breadcrumbs = accountBreadcrumbBuilder.getBreadcrumbs(null);
    breadcrumbs.add(
        new Breadcrumb(
            "/my-account/address-book",
            getMessageSource()
                .getMessage("text.account.addressBook", null, getI18nService().getCurrentLocale()),
            null));
    breadcrumbs.add(
        new Breadcrumb(
            "#",
            getMessageSource()
                .getMessage(
                    "text.account.addressBook.addEditAddress",
                    null,
                    getI18nService().getCurrentLocale()),
            null));
    model.addAttribute("breadcrumbs", breadcrumbs);
    model.addAttribute("metaRobots", "noindex,nofollow");
    model.addAttribute("edit", Boolean.TRUE);
    return getViewForPage(model);
  }