use of org.broadleafcommerce.profile.core.domain.CustomerForgotPasswordSecurityTokenImpl 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;
}
Aggregations