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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations