コード例 #1
0
  @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;
  }
コード例 #2
0
  @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);
  }
コード例 #3
0
  /**
   * 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());
    }
  }
コード例 #4
0
ファイル: SubscriptionAction.java プロジェクト: dmonga/work
  public void validateCustomer() {

    if (StringUtils.isBlank(customer.getCustomerEmailAddress())) {
      addFieldError("customer.customerEmailAddress", getText("messages.required.email"));
      super.addFieldMessage("customer.customerEmailAddress", "messages.required.email");
    } else {
      if (!CustomerUtil.validateEmail(customer.getCustomerEmailAddress())) {
        addFieldError("customer.customerEmailAddress", getText("messages.invalid.email"));
        super.addFieldMessage("customer.customerEmailAddress", "messages.invalid.email");
      }
    }
    /*
     * if(StringUtils.isBlank(customer.getCustomerPassword())) {
     * addFieldError("customer.customerPassword",
     * getText("messages.required.password")); }
     * if(StringUtils.isBlank(getConfirmEmailAddress())) {
     * addFieldError("confirmEmailAddress",
     * getText("messages.required.email.confirm")); }else{
     * if(!getConfirmEmailAddress
     * ().equals(customer.getCustomerEmailAddress())){
     * addFieldError("confirmEmailAddress",
     * getText("messages.unequal.email.confirm")); } }
     * if(StringUtils.isBlank(getConfirmPassword())) {
     * addFieldError("confirmPassword",
     * getText("messages.required.password.confirm")); }else{
     * if(!getConfirmPassword().equals(customer.getCustomerPassword())){
     * addFieldError("confirmPassword",
     * getText("messages.unequal.password.confirm")); } }
     */
    if (StringUtils.isBlank(customer.getCustomerFirstname())) {
      addFieldError("customer.customerFirstname", getText("messages.required.firstname"));
      super.addFieldMessage("customer.customerFirstname", "messages.required.firstname");
    }
    if (StringUtils.isBlank(customer.getCustomerLastname())) {
      addFieldError("customer.customerLastname", getText("messages.required.lastname"));
      super.addFieldMessage("customer.customerLastname", "messages.required.lastname");
    }
    if (StringUtils.isBlank(customer.getCustomerBillingStreetAddress())) {
      addFieldError(
          "customer.customerBillingStreetAddress", getText("messages.required.streetaddress"));
      super.addFieldMessage(
          "customer.customerBillingStreetAddress", "messages.required.streetaddress");
    }
    if (StringUtils.isBlank(customer.getCustomerBillingCity())) {
      addFieldError("customer.customerBillingCity", getText("messages.required.city"));
      super.addFieldMessage("customer.customerBillingCity", "messages.required.city");
    }
    if (!StringUtils.isBlank(this.getFormstate()) && this.getFormstate().equals("text")) {
      if (StringUtils.isBlank(customer.getCustomerBillingState())) {
        addFieldError("customer.customerBillingState", getText("messages.required.stateprovince"));
        super.addFieldMessage("customer.customerBillingState", "messages.required.stateprovince");
      }
    }
    if (StringUtils.isBlank(customer.getCustomerBillingPostalCode())) {
      addFieldError("customer.customerBillingPostalCode", getText("messages.required.postalcode"));
      super.addFieldMessage("customer.customerBillingPostalCode", "messages.required.postalcode");
    }

    if (StringUtils.isBlank(customer.getCustomerTelephone())) {
      addFieldError("customer.customerTelephone", getText("messages.required.phone"));
      super.addFieldMessage("customer.customerTelephone", "messages.required.phone");
    }
    /**
     * else if(!CustomerUtil.ValidatePhoneNumber(customer.getCustomerTelephone ())){
     * addFieldError("customer.customerTelephone", getText("messages.invalid.phone"));
     * super.addFieldMessage("customer.customerTelephone", "messages.invalid.phone"); }
     */
    String cName = "";
    Map lcountries = RefCache.getCountriesMap();
    if (lcountries != null) {
      Country country = (Country) lcountries.get(customer.getCustomerBillingCountryId());
      Set descriptions = country.getDescriptions();
      if (descriptions != null) {
        Iterator cIterator = descriptions.iterator();
        while (cIterator.hasNext()) {
          CountryDescription desc = (CountryDescription) cIterator.next();
          cName = desc.getCountryName();
          if (desc.getId().getLanguageId()
              == LanguageUtil.getLanguageNumberCode(super.getLocale().getLanguage())) {
            cName = desc.getCountryName();
            break;
          }
        }
      }
    }

    if (StringUtils.isBlank(customer.getCustomerBillingState())) {
      Map lzones =
          RefCache.getAllZonesmap(
              LanguageUtil.getLanguageNumberCode(super.getLocale().getLanguage()));
      if (lzones != null) {
        Zone z = (Zone) lzones.get(customer.getCustomerBillingZoneId());
        if (z != null) {
          customer.setCustomerBillingState(z.getZoneName());
          customer.setCustomerState(z.getZoneName());
        }
      }
    }

    String lang = super.getLocale().getLanguage();

    customer.setCountryName(cName);
    customer.setCustomerBillingCountryName(cName);
    customer.setCustomerLang(lang);

    customer.setCountryName(customer.getBillingCountry());
    customer.setCustomerCity(customer.getCustomerBillingCity());
    customer.setCustomerCountryId(customer.getCustomerBillingCountryId());
    customer.setCustomerLang(super.getLocale().getLanguage());
    customer.setCustomerPostalCode(customer.getCustomerBillingPostalCode());
    customer.setCustomerStreetAddress(customer.getCustomerBillingStreetAddress());
    customer.setCustomerState(customer.getBillingState());
    customer.setCustomerZoneId(customer.getCustomerBillingZoneId());
  }