Search in sources :

Example 1 with GenericResponse

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

the class AdminSecurityServiceImpl method sendResetPasswordNotification.

@Override
@Transactional("blTransactionManager")
public GenericResponse sendResetPasswordNotification(String username) {
    GenericResponse response = new GenericResponse();
    AdminUser user = null;
    if (username != null) {
        user = adminUserDao.readAdminUserByUserName(username);
    }
    checkUser(user, response);
    if (!response.getHasErrors()) {
        String token = PasswordUtils.generateSecurePassword(TEMP_PASSWORD_LENGTH);
        token = token.toLowerCase();
        ForgotPasswordSecurityToken fpst = new ForgotPasswordSecurityTokenImpl();
        fpst.setAdminUserId(user.getId());
        fpst.setToken(encodePassword(token, null));
        fpst.setCreateDate(SystemTime.asDate());
        forgotPasswordSecurityTokenDao.saveToken(fpst);
        HashMap<String, Object> vars = new HashMap<String, Object>();
        vars.put("token", token);
        String resetPasswordUrl = getResetPasswordURL();
        if (!StringUtils.isEmpty(resetPasswordUrl)) {
            if (resetPasswordUrl.contains("?")) {
                resetPasswordUrl = resetPasswordUrl + "&token=" + token;
            } else {
                resetPasswordUrl = resetPasswordUrl + "?token=" + token;
            }
        }
        vars.put("resetPasswordUrl", resetPasswordUrl);
        emailService.sendTemplateEmail(user.getEmail(), getResetPasswordEmailInfo(), vars);
    }
    return response;
}
Also used : ForgotPasswordSecurityToken(org.broadleafcommerce.openadmin.server.security.domain.ForgotPasswordSecurityToken) GenericResponse(org.broadleafcommerce.common.service.GenericResponse) ForgotPasswordSecurityTokenImpl(org.broadleafcommerce.openadmin.server.security.domain.ForgotPasswordSecurityTokenImpl) HashMap(java.util.HashMap) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with GenericResponse

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

the class CustomerServiceImpl method checkPasswordResetToken.

@Override
public GenericResponse checkPasswordResetToken(String token, Customer customer) {
    GenericResponse response = new GenericResponse();
    checkPasswordResetToken(token, customer, response);
    return response;
}
Also used : GenericResponse(org.broadleafcommerce.common.service.GenericResponse)

Example 3 with GenericResponse

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

the class CustomerServiceImpl method sendForgotPasswordNotification.

@Override
@Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
public GenericResponse sendForgotPasswordNotification(String username, String resetPasswordUrl) {
    GenericResponse response = new GenericResponse();
    Customer customer = null;
    if (username != null) {
        customer = customerDao.readCustomerByUsername(username);
    }
    checkCustomer(customer, response);
    if (!response.getHasErrors()) {
        String token = PasswordUtils.generateSecurePassword(getPasswordTokenLength());
        token = token.toLowerCase();
        Object salt = getSalt(customer, token);
        String saltString = null;
        if (salt != null) {
            saltString = Hex.encodeHexString(salt.toString().getBytes());
        }
        CustomerForgotPasswordSecurityToken fpst = new CustomerForgotPasswordSecurityTokenImpl();
        fpst.setCustomerId(customer.getId());
        fpst.setToken(encodePass(token, saltString));
        fpst.setCreateDate(SystemTime.asDate());
        customerForgotPasswordSecurityTokenDao.saveToken(fpst);
        if (usingDeprecatedPasswordEncoder() && saltString != null) {
            token = token + '-' + saltString;
        }
        HashMap<String, Object> vars = new HashMap<String, Object>();
        vars.put("token", token);
        if (!StringUtils.isEmpty(resetPasswordUrl)) {
            if (resetPasswordUrl.contains("?")) {
                resetPasswordUrl = resetPasswordUrl + "&token=" + token;
            } else {
                resetPasswordUrl = resetPasswordUrl + "?token=" + token;
            }
        }
        vars.put("resetPasswordUrl", resetPasswordUrl);
        sendEmail(customer.getEmailAddress(), getForgotPasswordEmailInfo(), vars);
    }
    return response;
}
Also used : CustomerForgotPasswordSecurityToken(org.broadleafcommerce.profile.core.domain.CustomerForgotPasswordSecurityToken) GenericResponse(org.broadleafcommerce.common.service.GenericResponse) Customer(org.broadleafcommerce.profile.core.domain.Customer) HashMap(java.util.HashMap) CustomerForgotPasswordSecurityTokenImpl(org.broadleafcommerce.profile.core.domain.CustomerForgotPasswordSecurityTokenImpl) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with GenericResponse

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

the class BroadleafLoginController method processResetPassword.

/**
 * Processes the reset password token and allows the user to change their password.
 * Ensures that the password and confirm password match, that the token is valid,
 * and that the token matches the provided email address.
 *
 * @param resetPasswordForm
 * @param request
 * @param response
 * @param model
 * @param errors
 * @return the return view
 * @throws ServiceException
 */
public String processResetPassword(ResetPasswordForm resetPasswordForm, HttpServletRequest request, HttpServletResponse response, Model model, BindingResult errors) throws ServiceException {
    resetPasswordValidator.validate(resetPasswordForm.getUsername(), resetPasswordForm.getPassword(), resetPasswordForm.getPasswordConfirm(), errors);
    if (errors.hasErrors()) {
        return getResetPasswordView();
    }
    GenericResponse errorResponse = customerService.resetPasswordUsingToken(resetPasswordForm.getUsername(), resetPasswordForm.getToken(), resetPasswordForm.getPassword(), resetPasswordForm.getPasswordConfirm());
    if (errorResponse.getHasErrors()) {
        String errorCode = errorResponse.getErrorCodesList().get(0);
        request.setAttribute("errorCode", errorCode);
        return getResetPasswordView();
    } else {
        // The reset password was successful, so log this customer in.
        loginService.loginCustomer(resetPasswordForm.getUsername(), resetPasswordForm.getPassword());
        return getResetPasswordSuccessView();
    }
}
Also used : GenericResponse(org.broadleafcommerce.common.service.GenericResponse)

Example 5 with GenericResponse

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

the class BroadleafLoginController method processForgotUsername.

/**
 * Looks up an account by email address and if found, sends an email with the
 * associated username.
 *
 * @param email
 * @param request
 * @param response
 * @param model
 * @return the return view
 */
public String processForgotUsername(String email, HttpServletRequest request, HttpServletResponse response, Model model) {
    GenericResponse errorResponse = customerService.sendForgotUsernameNotification(email);
    if (errorResponse.getHasErrors()) {
        String errorCode = errorResponse.getErrorCodesList().get(0);
        request.setAttribute("errorCode", errorCode);
        return getForgotUsernameView();
    } else {
        return buildRedirectToLoginWithMessage("usernameSent");
    }
}
Also used : GenericResponse(org.broadleafcommerce.common.service.GenericResponse)

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