use of org.broadleafcommerce.profile.core.domain.Customer 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.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class CustomerServiceImpl method registerCustomer.
@Override
@Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
public Customer registerCustomer(Customer customer, String password, String passwordConfirm) {
customer.setRegistered(true);
// When unencodedPassword is set the save() will encode it
if (customer.getId() == null) {
customer.setId(findNextCustomerId());
}
customer.setUnencodedPassword(password);
Customer retCustomer = saveCustomer(customer);
createRegisteredCustomerRoles(retCustomer);
HashMap<String, Object> vars = new HashMap<String, Object>();
vars.put("customer", retCustomer);
sendEmail(customer.getEmailAddress(), getRegistrationEmailInfo(), vars);
notifyPostRegisterListeners(retCustomer);
return retCustomer;
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class UserDetailsServiceImpl method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
Customer customer = customerService.readCustomerByUsername(username, false);
if (customer == null) {
throw new UsernameNotFoundException("The customer was not found");
}
List<GrantedAuthority> grantedAuthorities = createGrantedAuthorities(roleService.findCustomerRolesByCustomerId(customer.getId()));
return new CustomerUserDetails(customer.getId(), username, customer.getPassword(), !customer.isDeactivated(), true, !customer.isPasswordChangeRequired(), true, grantedAuthorities);
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafRegisterController method processRegister.
public String processRegister(RegisterCustomerForm registerCustomerForm, BindingResult errors, HttpServletRequest request, HttpServletResponse response, Model model) throws ServiceException, PricingException {
if (useEmailForLogin) {
Customer customer = registerCustomerForm.getCustomer();
customer.setUsername(customer.getEmailAddress());
}
registerCustomerValidator.validate(registerCustomerForm, errors, useEmailForLogin);
if (!errors.hasErrors()) {
Customer newCustomer = customerService.registerCustomer(registerCustomerForm.getCustomer(), registerCustomerForm.getPassword(), registerCustomerForm.getPasswordConfirm());
assert (newCustomer != null);
// The next line needs to use the customer from the input form and not the customer returned after registration
// so that we still have the unencoded password for use by the authentication mechanism.
loginService.loginCustomer(registerCustomerForm.getCustomer());
// Need to ensure that the Cart on CartState is owned by the newly registered customer.
Order cart = CartState.getCart();
if (cart != null && !(cart instanceof NullOrderImpl) && cart.getEmailAddress() == null) {
cart.setEmailAddress(newCustomer.getEmailAddress());
orderService.save(cart, false);
}
String redirectUrl = registerCustomerForm.getRedirectUrl();
if (StringUtils.isNotBlank(redirectUrl) && redirectUrl.contains(":")) {
redirectUrl = null;
}
return StringUtils.isBlank(redirectUrl) ? getRegisterSuccessView() : "redirect:" + redirectUrl;
} else {
return getRegisterView();
}
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafUpdateAccountController method processUpdateAccount.
public String processUpdateAccount(HttpServletRequest request, Model model, UpdateAccountForm form, BindingResult result, RedirectAttributes redirectAttributes) throws ServiceException {
updateAccountValidator.validate(form, result);
if (result.hasErrors()) {
return getUpdateAccountView();
}
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth == null || !auth.isAuthenticated()) {
throw new AuthenticationCredentialsNotFoundException("Authentication was null, not authenticated, or not logged in.");
}
Customer customer = CustomerState.getCustomer();
customer.setEmailAddress(form.getEmailAddress());
customer.setFirstName(form.getFirstName());
customer.setLastName(form.getLastName());
if (useEmailForLogin) {
customer.setUsername(form.getEmailAddress());
}
customer = customerService.saveCustomer(customer);
if (useEmailForLogin) {
UserDetails principal = userDetailsService.loadUserByUsername(customer.getUsername());
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), auth.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(token);
}
redirectAttributes.addFlashAttribute("successMessage", getAccountUpdatedMessage());
return getAccountRedirectView();
}
Aggregations