@Transactional public boolean changeCustomerPassword(Customer customer, String oldPassword, String newPassword) throws Exception { String key = EncryptionUtil.generatekey(String.valueOf(SecurityConstants.idConstant)); String encrypted = EncryptionUtil.encrypt(key, newPassword); String old = EncryptionUtil.encrypt(key, oldPassword); if (!customer.getCustomerPassword().equals(old)) { return false; } customer.setCustomerPassword(encrypted); MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService); // MerchantUserInformation minfo = mservice.getMerchantUserInfo(customer // .getMerchantId()); MerchantStore store = mservice.getMerchantStore(customer.getMerchantId()); customerDao.saveOrUptade(customer); // send email String l = config.getString("core.system.defaultlanguage", "en"); if (!StringUtils.isBlank(customer.getCustomerLang())) { l = customer.getCustomerLang(); } LabelUtil lhelper = LabelUtil.getInstance(); String subject = lhelper.getText(l, "label.profile.information"); String info = lhelper.getText(l, "label.email.customer.portalinfo"); String pass = lhelper.getText(l, "label.email.customer.passwordreset.text") + " " + newPassword; // @TODO replace suffix String url = "<a href=\"" + config.getString("core.accountmanagement.portal.url") + "\">" + config.getProperty("core.accountmanagement.portal.url") + "</a>"; String portalurl = lhelper.getText(l, "label.email.customer.portalurl") + " " + url; Map emailctx = new HashMap(); emailctx.put("EMAIL_STORE_NAME", store.getStorename()); emailctx.put("EMAIL_CUSTOMER_PASSWORD", pass); emailctx.put("EMAIL_CUSTOMER_PORTAL_INFO", info); emailctx.put("EMAIL_CUSTOMER_PORTAL_ENTRY", portalurl); emailctx.put("EMAIL_CONTACT_OWNER", store.getStoreemailaddress()); CommonService cservice = new CommonService(); cservice.sendHtmlEmail( customer.getCustomerEmailAddress(), subject, store, emailctx, "email_template_password_reset_customer.ftl", customer.getCustomerLang()); return true; }
/** * Reset a Customer password. Will also send an email the the customer with the new password * * @param customer * @throws Exception */ @Transactional(rollbackFor = {Exception.class}) public void resetCustomerPassword(Customer customer) throws Exception { MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService); MerchantStore store = mservice.getMerchantStore(customer.getMerchantId()); // MerchantUserInformation minfo = mservice.getMerchantUserInfo(customer // .getMerchantId()); if (!customer.isCustomerAnonymous()) { // generate password PasswordGeneratorModule passwordGenerator = (PasswordGeneratorModule) SpringUtil.getBean("passwordgenerator"); // encrypt String key = EncryptionUtil.generatekey(String.valueOf(SecurityConstants.idConstant)); boolean found = true; String password = null; String encrypted = null; // validate if already exist while (found) { password = passwordGenerator.generatePassword(); encrypted = EncryptionUtil.encrypt(key, password); Customer cfound = customerDao.findByUserNameAndPassword(customer.getCustomerNick(), encrypted); if (cfound == null) { found = false; } } // store in customer customer.setCustomerNick(customer.getCustomerEmailAddress()); customer.setCustomerPassword(encrypted); customerDao.saveOrUptade(customer); // send email String l = config.getString("core.system.defaultlanguage", "en"); if (!StringUtils.isBlank(customer.getCustomerLang())) { l = customer.getCustomerLang(); } LabelUtil lhelper = LabelUtil.getInstance(); String subject = lhelper.getText(l, "label.profile.information"); String info = lhelper.getText(l, "label.email.customer.portalinfo"); String pass = lhelper.getText(l, "label.email.customer.passwordreset.text") + " " + password; // @TODO replace suffix String url = "<a href=\"" + config.getString("core.accountmanagement.portal.url") + "\">" + config.getString("core.accountmanagement.portal.url") + "</a>"; String portalurl = lhelper.getText(l, "label.email.customer.portalurl") + " " + url; Map emailctx = new HashMap(); emailctx.put("EMAIL_STORE_NAME", store.getStorename()); emailctx.put("EMAIL_CUSTOMER_PASSWORD", pass); emailctx.put("EMAIL_CUSTOMER_PORTAL_INFO", info); emailctx.put("EMAIL_CONTACT_OWNER", store.getStoreemailaddress()); CommonService cservice = new CommonService(); cservice.sendHtmlEmail( customer.getCustomerEmailAddress(), subject, store, emailctx, "email_template_password_reset_customer.ftl", customer.getCustomerLang()); } }
/** Complete overwrite * */ public String comitOrder() { try { boolean paymentProcessed = false; // Get all entities Order order = SessionUtil.getOrder(getServletRequest()); MerchantStore store = SessionUtil.getMerchantStore(getServletRequest()); PaymentMethod payment = SessionUtil.getPaymentMethod(getServletRequest()); order.setPaymentMethod(payment.getPaymentMethodName()); order.setPaymentModuleCode(payment.getPaymentModuleName()); Customer customer = SessionUtil.getCustomer(getServletRequest()); if (super.getServletRequest().getSession().getAttribute("TRANSACTIONCOMITED") != null) { addActionError( getText( "error.transaction.duplicate", new String[] {String.valueOf(order.getOrderId()), store.getStoreemailaddress()})); return "GENERICERROR"; } OrderService oservice = (OrderService) ServiceFactory.getService(ServiceFactory.OrderService); try { Map orderProducts = SessionUtil.getOrderProducts(getServletRequest()); Set s = new HashSet(); for (Object o : orderProducts.values()) { OrderProduct op = (OrderProduct) o; s.add(op); } order.setOrderProducts(s); String comments = null; if (this.getOrderHistory() != null) { comments = this.getOrderHistory().getComments(); } // Order, PaymentMethod, ProcessorContext context = new ProcessorContext(); Collection files = oservice.getOrderProductDownloads(order.getOrderId()); if (files != null && files.size() > 0) { context.addObject("files", files); } context.addObject("Order", order); context.addObject("Customer", customer); context.addObject("MerchantStore", store); context.addObject("PaymentMethod", payment); context.addObject("Locale", super.getLocale()); context.addObject("comments", comments); context.addObject("products", orderProducts.values()); WorkflowProcessor wp = (WorkflowProcessor) SpringUtil.getBean("invoiceWorkflow"); wp.doWorkflow(context); paymentProcessed = true; // set an indicator in HTTPSession to prevent duplicates super.getServletRequest().getSession().setAttribute("TRANSACTIONCOMITED", "true"); if (!StringUtils.isBlank(comments)) { SessionUtil.setOrderStatusHistory(this.getOrderHistory(), getServletRequest()); } } catch (Exception e) { if (e instanceof TransactionException) { super.addErrorMessage("error.payment.paymenterror"); return "PAYMENTERROR"; } if (e instanceof OrderException) { try { oservice.sendOrderProblemEmail(order.getMerchantId(), order, customer, store); } catch (Exception ee) { log.error(ee); } } addActionError( getText( "message.error.comitorder.error", new String[] {String.valueOf(order.getOrderId()), store.getStoreemailaddress()})); log.error(e); return "GENERICERROR"; } return SUCCESS; } catch (Exception e) { log.error(e); } return SUCCESS; }
@Transactional(rollbackFor = {Exception.class}) public void saveOrUpdateCustomer(Customer customer, SystemUrlEntryType entryType, Locale locale) throws Exception { MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService); MerchantStore store = mservice.getMerchantStore(customer.getMerchantId()); // MerchantUserInformation minfo = mservice.getMerchantUserInfo(customer // .getMerchantId()); if (entryType == null) { entryType = SystemUrlEntryType.WEB; } // check if email aleady exist boolean isNew = false; if (customer.getCustomerId() == 0) { isNew = true; } if (isNew && !customer.isCustomerAnonymous()) { // generate password PasswordGeneratorModule passwordGenerator = (PasswordGeneratorModule) SpringUtil.getBean("passwordgenerator"); // encrypt String key = EncryptionUtil.generatekey(String.valueOf(SecurityConstants.idConstant)); boolean found = true; String password = null; String encrypted = null; // validate if already exist while (found) { password = passwordGenerator.generatePassword(); encrypted = EncryptionUtil.encrypt(key, password); Customer cfound = customerDao.findByUserNameAndPassword(customer.getCustomerNick(), encrypted); if (cfound == null) { found = false; } } // store in customer customer.setCustomerNick(customer.getCustomerEmailAddress()); customer.setCustomerPassword(encrypted); // send email String l = config.getString("core.system.defaultlanguage", "en"); if (!StringUtils.isBlank(customer.getCustomerLang())) { l = customer.getCustomerLang(); } LabelUtil lhelper = LabelUtil.getInstance(); String subject = lhelper.getText(l, "label.profile.information"); List params = new ArrayList(); params.add(store.getStorename()); String greeting = lhelper.getText(locale, "label.email.customer.greeting", params); String username = lhelper.getText(l, "label.generic.customer.username") + " " + customer.getCustomerNick(); String pass = lhelper.getText(l, "label.generic.customer.password") + " " + password; String info = ""; String portalurl = ""; if (entryType == SystemUrlEntryType.PORTAL) { info = lhelper.getText(l, "label.email.customer.portalinfo"); String url = "<a href=\"" + config.getProperty("core.accountmanagement.portal.url") + "/" + customer.getMerchantId() + "\">" + config.getProperty("core.accountmanagement.portal.url") + "/" + customer.getMerchantId() + "</a>"; portalurl = lhelper.getText(l, "label.email.customer.portalurl") + " " + url; } else { info = lhelper.getText(l, "label.email.customer.webinfo"); String url = "<a href=\"" + ReferenceUtil.buildCatalogUri(store) + "/\">" + ReferenceUtil.buildCatalogUri(store) + "/landing.action?merchantId=" + store.getMerchantId() + "</a>"; portalurl = lhelper.getText(l, "label.email.customer.weburl") + " " + url; } Map emailctx = new HashMap(); emailctx.put("EMAIL_STORE_NAME", store.getStorename()); emailctx.put("EMAIL_CUSTOMER_FIRSTNAME", customer.getCustomerFirstname()); emailctx.put("EMAIL_CUSTOMER_LAST", customer.getCustomerLastname()); emailctx.put("EMAIL_CUSTOMER_USERNAME", username); emailctx.put("EMAIL_CUSTOMER_PASSWORD", pass); emailctx.put("EMAIL_GREETING", greeting); emailctx.put("EMAIL_CUSTOMER_PORTAL_INFO", info); emailctx.put("EMAIL_CUSTOMER_PORTAL_ENTRY", portalurl); emailctx.put("EMAIL_CONTACT_OWNER", store.getStoreemailaddress()); CommonService cservice = new CommonService(); cservice.sendHtmlEmail( customer.getCustomerEmailAddress(), subject, store, emailctx, "email_template_customer.ftl", customer.getCustomerLang()); } customerDao.saveOrUptade(customer); // set CustomerInfo CustomerInfo customerInfo = new CustomerInfo(); customerInfo.setCustomerInfoId(customer.getCustomerId()); int login = customerInfo.getCustomerInfoNumberOfLogon(); customerInfo.setCustomerInfoNumberOfLogon(login++); customerInfo.setCustomerInfoDateOfLastLogon(new Date()); customerInfoDao.saveOrUpdate(customerInfo); }
/** * Validates input parameters for a new subscription request * * @return */ public boolean validateAddSubscription() { boolean success = true; if (value.getMerchantId() == 0) { addActionError( getText("error.validation.parameter.missing", new String[] {MERCHANT_ID_PARAM})); success = false; } if (value.getProductId() == 0) { addActionError( getText("error.validation.parameter.missing", new String[] {PRODUCT_ID_PARAM})); success = false; } if (success) { try { store = mservice.getMerchantStore(value.getMerchantId()); Collection<MerchantUserInformation> minfo = mservice.getMerchantUserInfo(value.getMerchantId()); if (store == null) { addActionError( getText( "error.merchant.unavailable", new String[] {String.valueOf(value.getMerchantId())})); return false; } // maybe this has to be done value.setCountryId(store.getCountry()); // @TODO log to CommonService Product product = cservice.getProduct(value.getProductId()); if (product == null || product.getMerchantId() != value.getMerchantId()) { LogMerchantUtil.log( value.getMerchantId(), getText( "error.validation.merchant.product.ids", new String[] { String.valueOf(value.getProductId()), String.valueOf(value.getMerchantId()) })); addActionError( getText( "error.validation.merchant.product.ids", new String[] { String.valueOf(value.getProductId()), String.valueOf(value.getMerchantId()) })); success = false; } else { if (product.getProductDateAvailable().after(new Date())) { LogMerchantUtil.log( value.getMerchantId(), getText( "error.product.unavailable.purchase", new String[] {String.valueOf(value.getProductId())})); addActionError( getText( "error.product.unavailable.purchase", new String[] {String.valueOf(value.getProductId())})); success = false; } if (product.getProductQuantity() == OUT_OF_STOCK_PRODUCT_QUANTITY) { LogMerchantUtil.log( value.getMerchantId(), getText( "error.product.unavailable.purchase", new String[] {String.valueOf(value.getProductId())})); addActionError( getText( "error.product.unavailable.purchase", new String[] {String.valueOf(value.getProductId())})); Configuration config = PropertiesUtil.getConfiguration(); // MerchantProfile profile = // mservice.getMerchantProfile(value.getMerchantId()); String l = config.getString("core.system.defaultlanguage", "en"); if (minfo == null) { log.error("MerchantUserInformation is null for merchantId " + value.getMerchantId()); addActionError( getText( "error.product.unavailable.purchase", new String[] {String.valueOf(value.getProductId())})); // goto global error throw new Exception("Invalid MerchantId,Unable to find MerchantProfile"); } MerchantUserInformation user = (MerchantUserInformation) ((List) minfo).get(0); if (!StringUtils.isBlank(user.getUserlang())) { l = user.getUserlang(); } String description = ""; Collection descriptionslist = product.getDescriptions(); if (descriptionslist != null) { Iterator i = descriptionslist.iterator(); while (i.hasNext()) { Object o = i.next(); if (o instanceof ProductDescription) { ProductDescription desc = (ProductDescription) o; description = desc.getProductName(); if (desc.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(l)) { description = desc.getProductName(); break; } } } } List params = new ArrayList(); params.add(description); params.add(product.getProductId()); LabelUtil lhelper = LabelUtil.getInstance(); String subject = lhelper.getText(super.getLocale(), "label.email.store.outofstock.subject"); String productId = lhelper.getText(super.getLocale(), "label.email.store.outofstock.product", params); Map emailctx = new HashMap(); emailctx.put("EMAIL_STORE_NAME", store.getStorename()); emailctx.put("EMAIL_PRODUCT_TEXT", productId); CommonService cservice = new CommonService(); cservice.sendHtmlEmail( store.getStoreemailaddress(), subject, store, emailctx, "email_template_outofstock.ftl", store.getDefaultLang()); success = false; } else if (product.getProductQuantity() < LOW_STOCK_PRODUCT_QUANTITY) { Configuration config = PropertiesUtil.getConfiguration(); // MerchantProfile profile = // mservice.getMerchantProfile(value.getMerchantId()); String l = config.getString("core.system.defaultlanguage", "en"); if (minfo == null) { log.error("MerchantUserInformationis null for merchantId " + value.getMerchantId()); addActionError( getText( "error.product.unavailable.purchase", new String[] {String.valueOf(value.getProductId())})); // goto global error throw new Exception("Invalid MerchantId,Unable to find MerchantProfile"); } MerchantUserInformation user = (MerchantUserInformation) ((List) minfo).get(0); if (!StringUtils.isBlank(user.getUserlang())) { l = user.getUserlang(); } String description = ""; Collection descriptionslist = product.getDescriptions(); if (descriptionslist != null) { Iterator i = descriptionslist.iterator(); while (i.hasNext()) { Object o = i.next(); if (o instanceof ProductDescription) { ProductDescription desc = (ProductDescription) o; description = desc.getProductName(); if (desc.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(l)) { description = desc.getProductName(); break; } } } } List params = new ArrayList(); params.add(description); params.add(product.getProductId()); LabelUtil lhelper = LabelUtil.getInstance(); String subject = lhelper.getText(l, "label.email.store.lowinventory.subject"); String productId = lhelper.getText( super.getLocale(), "label.email.store.lowinventory.product", params); Map emailctx = new HashMap(); emailctx.put("EMAIL_STORE_NAME", store.getStorename()); emailctx.put("EMAIL_PRODUCT_TEXT", productId); CommonService cservice = new CommonService(); cservice.sendHtmlEmail( store.getStoreemailaddress(), subject, store, emailctx, "email_template_lowstock.ftl", store.getDefaultLang()); } } } catch (Exception e) { log.error("Exception occurred while getting product by Id", e); addActionError(getText("errors.technical")); } } return success; }