protected String getKnownEmailAddress(Order cart, Customer customer) { String emailAddress = null; if (cart.getEmailAddress() != null) { emailAddress = cart.getEmailAddress(); } else if (customer != null && customer.getEmailAddress() != null) { emailAddress = customer.getEmailAddress(); } return emailAddress; }
protected void setNewCartOwnership(Order cart, Customer customer) { cart.setCustomer(customer); // copy the customer's email to this order, overriding any previously set email if (cart != null && StringUtils.isNotBlank(customer.getEmailAddress())) { cart.setEmailAddress(customer.getEmailAddress()); } extensionManager.getProxy().setNewCartOwnership(cart, customer); }
protected void checkCustomer(Customer customer, GenericResponse response) { if (customer == null) { response.addErrorCode("invalidCustomer"); } else if (StringUtils.isBlank(customer.getEmailAddress())) { response.addErrorCode("emailNotFound"); } else if (customer.isDeactivated()) { response.addErrorCode("inactiveUser"); } }
/** * Validates that a Customer does not have their username duplicated * * @param entity * @param adminInstance * @return the original entity with a validation error on it or null if no validation failure */ protected Entity validateUniqueUsername(Entity entity, Customer adminInstance, boolean isAdd) { String email = entity.findProperty("emailAddress").getValue(); boolean skipUsernameCheck = !isAdd && StringUtils.equals(email, adminInstance.getEmailAddress()); if (!skipUsernameCheck && customerService.readCustomerByUsername(email) != null) { entity.addValidationError("emailAddress", "nonUniqueUsernameError"); return entity; } return null; }
@Override public void processRegistrationEvent(Customer customer) { List<Order> orders = orderService.findOrdersByEmail(customer.getEmailAddress()); List<Order> updOrders = new ArrayList<>(); for (Order o : orders) { if (!o.getCustomer().isRegistered()) { o.setCustomer(customer); updOrders.add(o); } } List<PostUpdateOrderExtensionHandler> handlers = extensionManager.getHandlers(); for (PostUpdateOrderExtensionHandler h : handlers) { ExtensionResultStatusType status = h.postUpdateAll(updOrders); if (!extensionManager.shouldContinue(status, null, null, null)) { break; } } } }
@Override @Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER) public Customer registerCustomer(Customer customer, String password, String passwordConfirm) { customer.setRegistered(true); // When unencodedPassword is set the save() will encode it if (customer.getId() == null) { customer.setId(findNextCustomerId()); } customer.setUnencodedPassword(password); Customer retCustomer = saveCustomer(customer); createRegisteredCustomerRoles(retCustomer); HashMap<String, Object> vars = new HashMap<String, Object>(); vars.put("customer", retCustomer); sendEmail(customer.getEmailAddress(), getRegistrationEmailInfo(), vars); notifyPostRegisterListeners(retCustomer); return retCustomer; }
@Override public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { Entity entity = persistencePackage.getEntity(); Customer customer = customerService.readCustomerByUsername(entity.findProperty("username").getValue()); if (StringUtils.isEmpty(customer.getEmailAddress())) { throw new ServiceException("Unable to update password because an email address is not available for this customer. An email address is required to send the customer the new system generated password."); } PasswordReset passwordReset = new PasswordReset(); passwordReset.setUsername(entity.findProperty("username").getValue()); passwordReset.setPasswordChangeRequired(false); passwordReset.setEmail(customer.getEmailAddress()); passwordReset.setPasswordLength(22); passwordReset.setSendResetEmailReliableAsync(false); customer = customerService.resetPassword(passwordReset); return entity; }
customer.setUsername(customer.getEmailAddress()); cart.setEmailAddress(newCustomer.getEmailAddress()); orderService.save(cart, false);
sendEmail(customer.getEmailAddress(), getForgotPasswordEmailInfo(), vars);
public String viewUpdateAccount(HttpServletRequest request, Model model, UpdateAccountForm form) { Customer customer = CustomerState.getCustomer(); form.setEmailAddress(customer.getEmailAddress()); form.setFirstName(customer.getFirstName()); form.setLastName(customer.getLastName()); return getUpdateAccountView(); }
@Override public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { Entity entity = persistencePackage.getEntity(); try { PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective(); Customer adminInstance = (Customer) Class.forName(entity.getType()[0]).newInstance(); adminInstance.setId(customerService.findNextCustomerId()); Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective); adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false); if (useEmailForLogin) { adminInstance.setUsername(adminInstance.getEmailAddress()); } Entity errorEntity = validateUniqueUsername(entity, adminInstance, true); if (errorEntity != null) { return errorEntity; } adminInstance = dynamicEntityDao.merge(adminInstance); customerService.createRegisteredCustomerRoles(adminInstance); Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null); return adminEntity; } catch (Exception e) { LOG.error("Unable to execute persistence activity", e); throw new ServiceException("Unable to add entity for " + entity.getType()[0], e); } }
@Override public PaymentRequestDTO populateCustomerInfo(PaymentRequestDTO requestDTO, Customer customer, String defaultEmailAddress) { String phoneNumber = null; for (CustomerPhone phone : ListUtils.emptyIfNull(customer.getCustomerPhones())) { if (phone.getPhone().isDefault()) { phoneNumber = phone.getPhone().getPhoneNumber(); } } String emailAddress = (customer.getEmailAddress() == null)? defaultEmailAddress : customer.getEmailAddress(); return requestDTO.customer() .customerId(customer.getId().toString()) .firstName(customer.getFirstName()) .lastName(customer.getLastName()) .email(emailAddress) .phone(phoneNumber) .done(); } }
if (customerCart != null && StringUtils.isNotBlank(customer.getEmailAddress())) { customerCart.setEmailAddress(customer.getEmailAddress()); customerCart = orderService.save(customerCart, priceOrder);
if (isUseEmailForLogin()) { Customer customer = registerCustomerForm.getCustomer(); customer.setUsername(customer.getEmailAddress()); cart.setEmailAddress(newCustomer.getEmailAddress()); orderService.save(cart, false);
public void validate(Customer customer, String password, String passwordConfirm, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirm", "passwordConfirm.required"); errors.pushNestedPath("customer"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); errors.popNestedPath(); if (errors.hasErrors()){ if (!passwordConfirm.equals(password)) { errors.rejectValue("passwordConfirm", "invalid"); } if (!customer.getFirstName().matches(getValidNameRegex())) { errors.rejectValue("firstName", "firstName.invalid", null, null); } if (!customer.getLastName().matches(getValidNameRegex())) { errors.rejectValue("lastName", "lastName.invalid", null, null); } if (!customer.getPassword().matches(getValidPasswordRegex())) { errors.rejectValue("password", "password.invalid", null, null); } if (!password.equals(passwordConfirm)) { errors.rejectValue("password", "passwordConfirm.invalid", null, null); } if (!GenericValidator.isEmail(customer.getEmailAddress())) { errors.rejectValue("emailAddress", "emailAddress.invalid", null, null); } } }
@Override public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { Entity entity = persistencePackage.getEntity(); try { PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective(); Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective); Object primaryKey = helper.getPrimaryKey(entity, adminProperties); Customer adminInstance = (Customer) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey); Entity errorEntity = validateUniqueUsername(entity, adminInstance, false); if (errorEntity != null) { return errorEntity; } String passwordBefore = adminInstance.getPassword(); adminInstance.setPassword(null); adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false); adminInstance.setPassword(passwordBefore); if (useEmailForLogin) { adminInstance.setUsername(adminInstance.getEmailAddress()); } adminInstance = customerService.saveCustomer(adminInstance); Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null); return adminEntity; } catch (Exception e) { throw new ServiceException("Unable to update entity for " + entity.getType()[0], e); } }
order.setEmailAddress(customer.getEmailAddress()); order.setStatus(OrderStatus.IN_PROCESS);
public void validate(Object obj, Errors errors, boolean useEmailForUsername) { RegisterCustomerForm form = (RegisterCustomerForm) obj; Customer customerFromDb = customerService.readCustomerByUsername(form.getCustomer().getUsername()); if (customerFromDb != null && customerFromDb.isRegistered()) { if (useEmailForUsername) { errors.rejectValue("customer.emailAddress", "emailAddress.used", null, null); } else { errors.rejectValue("customer.username", "username.used", null, null); } } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirm", "passwordConfirm.required"); errors.pushNestedPath("customer"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); errors.popNestedPath(); if (!errors.hasErrors()) { if (!form.getPassword().matches(getValidatePasswordExpression())) { errors.rejectValue("password", "password.invalid", null, null); } if (!form.getPassword().equals(form.getPasswordConfirm())) { errors.rejectValue("password", "passwordConfirm.invalid", null, null); } if (!GenericValidator.isEmail(form.getCustomer().getEmailAddress())) { errors.rejectValue("customer.emailAddress", "emailAddress.invalid", null, null); } } }
customer.setLastName(gatewayCustomer.getLastName()); if (StringUtils.isEmpty(customer.getEmailAddress()) && gatewayCustomer != null) { customer.setEmailAddress(gatewayCustomer.getEmail());
@Override public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { Entity entity = persistencePackage.getEntity(); Customer customer = customerService.readCustomerByUsername(entity.findProperty("username").getValue()); if (StringUtils.isEmpty(customer.getEmailAddress())) { throw new ServiceException("Unable to update password because an email address is not available for this customer. An email address is required to send the customer the new system generated password."); } PasswordReset passwordReset = new PasswordReset(); passwordReset.setUsername(entity.findProperty("username").getValue()); passwordReset.setPasswordChangeRequired(false); passwordReset.setEmail(customer.getEmailAddress()); passwordReset.setPasswordLength(22); passwordReset.setSendResetEmailReliableAsync(false); customer = customerService.resetPassword(passwordReset); return entity; }