@PreAuthorize("hasRole('STORE')") @RequestMapping(value = "/admin/store/saveTemplate.html", method = RequestMethod.POST) public String saveTemplate( @ModelAttribute(value = "store") final MerchantStore store, BindingResult result, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception { setMenu(model, request); MerchantStore sessionstore = (MerchantStore) request.getAttribute(Constants.ADMIN_STORE); sessionstore.setStoreTemplate(store.getStoreTemplate()); merchantStoreService.saveOrUpdate(sessionstore); request.setAttribute(Constants.ADMIN_STORE, sessionstore); // display templates model.addAttribute("templates", templates); model.addAttribute("success", "success"); model.addAttribute("store", sessionstore); return "admin-store-branding"; }
@RequestMapping(value = "/registration.html", method = RequestMethod.GET) public String displayRegistration( final Model model, final HttpServletRequest request, final HttpServletResponse response) throws Exception { MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE); model.addAttribute( "recapatcha_public_key", coreConfiguration.getProperty(Constants.RECAPATCHA_PUBLIC_KEY)); SecuredShopPersistableCustomer customer = new SecuredShopPersistableCustomer(); AnonymousCustomer anonymousCustomer = (AnonymousCustomer) request.getAttribute(Constants.ANONYMOUS_CUSTOMER); if (anonymousCustomer != null) { customer.setBilling(anonymousCustomer.getBilling()); } model.addAttribute("customer", customer); /** template * */ StringBuilder template = new StringBuilder() .append(ControllerConstants.Tiles.Customer.register) .append(".") .append(store.getStoreTemplate()); return template.toString(); }
@RequestMapping("/shop/store/contactus.html") public String displayContact( Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception { MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE); Language language = (Language) request.getAttribute("LANGUAGE"); ContactForm contact = new ContactForm(); model.addAttribute("contact", contact); model.addAttribute( "recapatcha_public_key", coreConfiguration.getProperty(Constants.RECAPATCHA_PUBLIC_KEY)); Content content = contentService.getByCode(Constants.CONTENT_CONTACT_US, store, language); ContentDescription contentDescription = null; if (content != null && content.isVisible()) { contentDescription = content.getDescription(); } if (contentDescription != null) { // meta information PageInformation pageInformation = new PageInformation(); pageInformation.setPageDescription(contentDescription.getMetatagDescription()); pageInformation.setPageKeywords(contentDescription.getMetatagKeywords()); pageInformation.setPageTitle(contentDescription.getTitle()); pageInformation.setPageUrl(contentDescription.getName()); request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation); model.addAttribute("content", contentDescription); } /** template * */ StringBuilder template = new StringBuilder() .append(ControllerConstants.Tiles.Content.contactus) .append(".") .append(store.getStoreTemplate()); return template.toString(); }
@RequestMapping( value = {"/shop/home.html", "/shop/", "/shop"}, method = RequestMethod.GET) public String displayLanding( Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception { Language language = (Language) request.getAttribute(Constants.LANGUAGE); MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE); Content content = contentService.getByCode("LANDING_PAGE", store, language); /** Rebuild breadcrumb * */ BreadcrumbItem item = new BreadcrumbItem(); item.setItemType(BreadcrumbItemType.HOME); item.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, locale)); item.setUrl(Constants.HOME_URL); Breadcrumb breadCrumb = new Breadcrumb(); breadCrumb.setLanguage(language); List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>(); items.add(item); breadCrumb.setBreadCrumbs(items); request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb); request.setAttribute(Constants.BREADCRUMB, breadCrumb); /** * */ if (content != null) { ContentDescription description = content.getDescription(); model.addAttribute("page", description); PageInformation pageInformation = new PageInformation(); pageInformation.setPageTitle(description.getName()); pageInformation.setPageDescription(description.getMetatagDescription()); pageInformation.setPageKeywords(description.getMetatagKeywords()); request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation); } ReadableProductPopulator populator = new ReadableProductPopulator(); populator.setPricingService(pricingService); // featured items List<ProductRelationship> relationships = productRelationshipService.getByType( store, ProductRelationshipType.FEATURED_ITEM, language); List<ReadableProduct> featuredItems = new ArrayList<ReadableProduct>(); for (ProductRelationship relationship : relationships) { Product product = relationship.getRelatedProduct(); ReadableProduct proxyProduct = populator.populate(product, new ReadableProduct(), store, language); featuredItems.add(proxyProduct); } model.addAttribute("featuredItems", featuredItems); /** template * */ StringBuilder template = new StringBuilder().append("landing.").append(store.getStoreTemplate()); return template.toString(); }
@RequestMapping(value = "/register.html", method = RequestMethod.POST) public String registerCustomer( @Valid @ModelAttribute("customer") SecuredShopPersistableCustomer customer, BindingResult bindingResult, Model model, HttpServletRequest request, final Locale locale) throws Exception { MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE); Language language = super.getLanguage(request); ReCaptchaImpl reCaptcha = new ReCaptchaImpl(); reCaptcha.setPublicKey(coreConfiguration.getProperty(Constants.RECAPATCHA_PUBLIC_KEY)); reCaptcha.setPrivateKey(coreConfiguration.getProperty(Constants.RECAPATCHA_PRIVATE_KEY)); String userName = null; String password = null; model.addAttribute( "recapatcha_public_key", coreConfiguration.getProperty(Constants.RECAPATCHA_PUBLIC_KEY)); if (StringUtils.isNotBlank(customer.getRecaptcha_challenge_field()) && StringUtils.isNotBlank(customer.getRecaptcha_response_field())) { ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer( request.getRemoteAddr(), customer.getRecaptcha_challenge_field(), customer.getRecaptcha_response_field()); if (!reCaptchaResponse.isValid()) { LOGGER.debug("Captcha response does not matched"); FieldError error = new FieldError( "recaptcha_challenge_field", "recaptcha_challenge_field", messages.getMessage("validaion.recaptcha.not.matched", locale)); bindingResult.addError(error); } } if (StringUtils.isNotBlank(customer.getUserName())) { if (customerFacade.checkIfUserExists(customer.getUserName(), merchantStore)) { LOGGER.debug( "Customer with username {} already exists for this store ", customer.getUserName()); FieldError error = new FieldError( "userName", "userName", messages.getMessage("registration.username.already.exists", locale)); bindingResult.addError(error); } userName = customer.getUserName(); } if (StringUtils.isNotBlank(customer.getPassword()) && StringUtils.isNotBlank(customer.getCheckPassword())) { if (!customer.getPassword().equals(customer.getCheckPassword())) { FieldError error = new FieldError( "password", "password", messages.getMessage("message.password.checkpassword.identical", locale)); bindingResult.addError(error); } password = customer.getPassword(); } if (bindingResult.hasErrors()) { LOGGER.debug( "found {} validation error while validating in customer registration ", bindingResult.getErrorCount()); StringBuilder template = new StringBuilder() .append(ControllerConstants.Tiles.Customer.register) .append(".") .append(merchantStore.getStoreTemplate()); return template.toString(); } @SuppressWarnings("unused") CustomerEntity customerData = null; try { customerData = customerFacade.registerCustomer(customer, merchantStore, language); } catch (CustomerRegistrationException cre) { LOGGER.error("Error while registering customer.. ", cre); ObjectError error = new ObjectError("registration", messages.getMessage("registration.failed", locale)); bindingResult.addError(error); StringBuilder template = new StringBuilder() .append(ControllerConstants.Tiles.Customer.register) .append(".") .append(merchantStore.getStoreTemplate()); return template.toString(); } catch (Exception e) { LOGGER.error("Error while registering customer.. ", e); ObjectError error = new ObjectError("registration", messages.getMessage("registration.failed", locale)); bindingResult.addError(error); StringBuilder template = new StringBuilder() .append(ControllerConstants.Tiles.Customer.register) .append(".") .append(merchantStore.getStoreTemplate()); return template.toString(); } /** Send registration email */ emailTemplatesUtils.sendRegistrationEmail( customer, merchantStore, locale, request.getContextPath()); /** Login user */ try { // refresh customer Customer c = customerFacade.getCustomerByUserName(customer.getUserName(), merchantStore); // authenticate customerFacade.authenticate(c, userName, password); super.setSessionAttribute(Constants.CUSTOMER, c, request); return "redirect:/shop/customer/dashboard.html"; } catch (Exception e) { LOGGER.error("Cannot authenticate user ", e); ObjectError error = new ObjectError("registration", messages.getMessage("registration.failed", locale)); bindingResult.addError(error); } StringBuilder template = new StringBuilder() .append(ControllerConstants.Tiles.Customer.register) .append(".") .append(merchantStore.getStoreTemplate()); return template.toString(); }