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