Search in sources :

Example 56 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class CustomerServiceImpl method sendForgotUsernameNotification.

@Override
@Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
public GenericResponse sendForgotUsernameNotification(String emailAddress) {
    GenericResponse response = new GenericResponse();
    List<Customer> customers = null;
    if (emailAddress != null) {
        customers = customerDao.readCustomersByEmail(emailAddress);
    }
    if (CollectionUtils.isEmpty(customers)) {
        response.addErrorCode("notFound");
    } else {
        List<String> activeUsernames = new ArrayList<String>();
        for (Customer customer : customers) {
            if (!customer.isDeactivated()) {
                activeUsernames.add(customer.getUsername());
            }
        }
        if (activeUsernames.size() > 0) {
            HashMap<String, Object> vars = new HashMap<String, Object>();
            vars.put("userNames", activeUsernames);
            sendEmail(emailAddress, getForgotUsernameEmailInfo(), vars);
        } else {
            // send inactive username found email.
            response.addErrorCode("inactiveUser");
        }
    }
    return response;
}
Also used : GenericResponse(org.broadleafcommerce.common.service.GenericResponse) Customer(org.broadleafcommerce.profile.core.domain.Customer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 57 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class CustomerServiceImpl method resetPassword.

@Override
@Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
public Customer resetPassword(PasswordReset passwordReset) {
    Customer customer = readCustomerByUsername(passwordReset.getUsername());
    String newPassword = PasswordUtils.generateSecurePassword(passwordReset.getPasswordLength());
    customer.setUnencodedPassword(newPassword);
    customer.setPasswordChangeRequired(passwordReset.getPasswordChangeRequired());
    customer = saveCustomer(customer);
    for (PasswordUpdatedHandler handler : passwordResetHandlers) {
        handler.passwordChanged(passwordReset, customer, newPassword);
    }
    return customer;
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) PasswordUpdatedHandler(org.broadleafcommerce.profile.core.service.handler.PasswordUpdatedHandler) Transactional(org.springframework.transaction.annotation.Transactional)

Example 58 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class CustomerServiceImpl method changePassword.

@Override
@Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
public Customer changePassword(PasswordChange passwordChange) {
    Customer customer = readCustomerByUsername(passwordChange.getUsername());
    customer.setUnencodedPassword(passwordChange.getNewPassword());
    customer.setPasswordChangeRequired(passwordChange.getPasswordChangeRequired());
    customer = saveCustomer(customer);
    for (PasswordUpdatedHandler handler : passwordChangedHandlers) {
        handler.passwordChanged(passwordChange, customer, passwordChange.getNewPassword());
    }
    return customer;
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) PasswordUpdatedHandler(org.broadleafcommerce.profile.core.service.handler.PasswordUpdatedHandler) Transactional(org.springframework.transaction.annotation.Transactional)

Example 59 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class CustomerServiceImpl method resetPasswordUsingToken.

@Override
@Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
public GenericResponse resetPasswordUsingToken(String username, String token, String password, String confirmPassword) {
    GenericResponse response = new GenericResponse();
    Customer customer = null;
    if (username != null) {
        customer = customerDao.readCustomerByUsername(username);
    }
    checkCustomer(customer, response);
    checkPassword(password, confirmPassword, response);
    CustomerForgotPasswordSecurityToken fpst = checkPasswordResetToken(token, customer, response);
    if (!response.getHasErrors()) {
        if (!customer.getId().equals(fpst.getCustomerId())) {
            if (LOG.isWarnEnabled()) {
                LOG.warn("Password reset attempt tried with mismatched customer and token " + customer.getId() + ", " + StringUtil.sanitize(token));
            }
            response.addErrorCode("invalidToken");
        }
    }
    if (!response.getHasErrors()) {
        customer.setUnencodedPassword(password);
        customer.setPasswordChangeRequired(false);
        saveCustomer(customer);
        invalidateAllTokensForCustomer(customer);
    }
    return response;
}
Also used : CustomerForgotPasswordSecurityToken(org.broadleafcommerce.profile.core.domain.CustomerForgotPasswordSecurityToken) GenericResponse(org.broadleafcommerce.common.service.GenericResponse) Customer(org.broadleafcommerce.profile.core.domain.Customer) Transactional(org.springframework.transaction.annotation.Transactional)

Example 60 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class RestApiCustomerStateFilter method doFilter.

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    String customerId = null;
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    // If someone already set the customer on the request then we don't need to do anything.
    if (request.getAttribute(CustomerStateRequestProcessor.getCustomerRequestAttributeName()) == null) {
        // First check to see if someone already put the customerId on the request
        if (request.getAttribute(CUSTOMER_ID_ATTRIBUTE) != null) {
            customerId = String.valueOf(request.getAttribute(CUSTOMER_ID_ATTRIBUTE));
        }
        if (customerId == null) {
            // If it's not on the request attribute, try the parameter
            customerId = servletRequest.getParameter(CUSTOMER_ID_ATTRIBUTE);
        }
        if (customerId == null) {
            // If it's not on the request parameter, look on the header
            customerId = request.getHeader(CUSTOMER_ID_ATTRIBUTE);
        }
        if (customerId != null && customerId.trim().length() > 0) {
            if (NumberUtils.isNumber(customerId)) {
                // If we found it, look up the customer and put it on the request.
                Customer customer = customerService.readCustomerById(Long.valueOf(customerId));
                if (customer != null) {
                    CustomerState.setCustomer(customer);
                    setupCustomerForRuleProcessing(customer, request);
                }
            } else {
                LOG.warn(String.format("The customer id passed in '%s' was not a number", StringUtil.sanitize(customerId)));
            }
        }
        if (customerId == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No customer ID was found for the API request. In order to look up a customer for the request" + " send a request parameter or request header for the '" + CUSTOMER_ID_ATTRIBUTE + "' attribute");
            }
        }
    }
    filterChain.doFilter(request, servletResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Customer(org.broadleafcommerce.profile.core.domain.Customer)

Aggregations

Customer (org.broadleafcommerce.profile.core.domain.Customer)98 Order (org.broadleafcommerce.core.order.domain.Order)41 Transactional (org.springframework.transaction.annotation.Transactional)34 Test (org.testng.annotations.Test)33 Address (org.broadleafcommerce.profile.core.domain.Address)14 Rollback (org.springframework.test.annotation.Rollback)11 HashMap (java.util.HashMap)9 CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)9 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)8 MergeCartResponse (org.broadleafcommerce.core.order.service.call.MergeCartResponse)6 ArrayList (java.util.ArrayList)5 Money (org.broadleafcommerce.common.money.Money)5 Category (org.broadleafcommerce.core.catalog.domain.Category)5 Product (org.broadleafcommerce.core.catalog.domain.Product)5 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)5 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)5 CustomerImpl (org.broadleafcommerce.profile.core.domain.CustomerImpl)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)3 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)3