Search in sources :

Example 6 with GenericResponse

use of org.broadleafcommerce.common.service.GenericResponse in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafLoginController method processForgotPassword.

/**
 * Looks up the passed in username and sends an email to the address on file with a
 * reset password token.
 *
 * Returns error codes for invalid username.
 *
 * @param username
 * @param request
 * @param model
 * @return the return view
 */
public String processForgotPassword(String username, HttpServletRequest request, Model model) {
    GenericResponse errorResponse = customerService.sendForgotPasswordNotification(username, getResetPasswordUrl(request));
    if (errorResponse.getHasErrors()) {
        String errorCode = errorResponse.getErrorCodesList().get(0);
        model.addAttribute("errorCode", errorCode);
        return getForgotPasswordView();
    } else {
        if (BLCRequestUtils.isOKtoUseSession(new ServletWebRequest(request))) {
            request.getSession(true).setAttribute(CHANGE_PASSWORD_USERNAME_REQUEST_ATTR, username);
        }
        return getForgotPasswordSuccessView();
    }
}
Also used : GenericResponse(org.broadleafcommerce.common.service.GenericResponse) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest)

Example 7 with GenericResponse

use of org.broadleafcommerce.common.service.GenericResponse in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafLoginController method processForcedPasswordChange.

public String processForcedPasswordChange(String username, HttpServletRequest request, Model model) {
    final String resetPasswordUrl = getResetPasswordUrl(request);
    final GenericResponse errorResponse = customerService.sendForcedPasswordChangeNotification(username, resetPasswordUrl);
    if (errorResponse.getHasErrors()) {
        final String errorCode = errorResponse.getErrorCodesList().get(0);
        model.addAttribute("errorCode", errorCode);
        return getForcedPasswordChangeView();
    } else {
        if (BLCRequestUtils.isOKtoUseSession(new ServletWebRequest(request))) {
            request.getSession(true).setAttribute(CHANGE_PASSWORD_USERNAME_REQUEST_ATTR, username);
        }
        return getForcedPasswordChangeSuccessView();
    }
}
Also used : GenericResponse(org.broadleafcommerce.common.service.GenericResponse) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest)

Example 8 with GenericResponse

use of org.broadleafcommerce.common.service.GenericResponse 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 9 with GenericResponse

use of org.broadleafcommerce.common.service.GenericResponse 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 10 with GenericResponse

use of org.broadleafcommerce.common.service.GenericResponse in project BroadleafCommerce by BroadleafCommerce.

the class AdminSecurityServiceImpl method sendForgotUsernameNotification.

@Override
@Transactional("blTransactionManager")
public GenericResponse sendForgotUsernameNotification(String emailAddress) {
    GenericResponse response = new GenericResponse();
    List<AdminUser> users = null;
    if (emailAddress != null) {
        users = adminUserDao.readAdminUserByEmail(emailAddress);
    }
    if (CollectionUtils.isEmpty(users)) {
        response.addErrorCode("notFound");
    } else {
        List<String> activeUsernames = new ArrayList<String>();
        for (AdminUser user : users) {
            if (user.getActiveStatusFlag()) {
                activeUsernames.add(user.getLogin());
            }
        }
        if (activeUsernames.size() > 0) {
            HashMap<String, Object> vars = new HashMap<String, Object>();
            vars.put("accountNames", activeUsernames);
            emailService.sendTemplateEmail(emailAddress, getSendUsernameEmailInfo(), vars);
        } else {
            // send inactive username found email.
            response.addErrorCode("inactiveUser");
        }
    }
    return response;
}
Also used : GenericResponse(org.broadleafcommerce.common.service.GenericResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

GenericResponse (org.broadleafcommerce.common.service.GenericResponse)12 Transactional (org.springframework.transaction.annotation.Transactional)7 HashMap (java.util.HashMap)4 AdminUser (org.broadleafcommerce.openadmin.server.security.domain.AdminUser)4 Customer (org.broadleafcommerce.profile.core.domain.Customer)3 ArrayList (java.util.ArrayList)2 ForgotPasswordSecurityToken (org.broadleafcommerce.openadmin.server.security.domain.ForgotPasswordSecurityToken)2 CustomerForgotPasswordSecurityToken (org.broadleafcommerce.profile.core.domain.CustomerForgotPasswordSecurityToken)2 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)2 ForgotPasswordSecurityTokenImpl (org.broadleafcommerce.openadmin.server.security.domain.ForgotPasswordSecurityTokenImpl)1 CustomerForgotPasswordSecurityTokenImpl (org.broadleafcommerce.profile.core.domain.CustomerForgotPasswordSecurityTokenImpl)1