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