use of com.salesmanager.shop.model.customer.CustomerPassword in project shopizer by shopizer-ecommerce.
the class CustomerAccountController method displayCustomerChangePassword.
@PreAuthorize("hasRole('AUTH_CUSTOMER')")
@RequestMapping(value = "/password.html", method = RequestMethod.GET)
public String displayCustomerChangePassword(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
CustomerPassword customerPassword = new CustomerPassword();
model.addAttribute("password", customerPassword);
/**
* template *
*/
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Customer.changePassword).append(".").append(store.getStoreTemplate());
return template.toString();
}
use of com.salesmanager.shop.model.customer.CustomerPassword in project shopizer by shopizer-ecommerce.
the class CustomerAccountController method changePassword.
@PreAuthorize("hasRole('AUTH_CUSTOMER')")
@RequestMapping(value = "/changePassword.html", method = RequestMethod.POST)
public String changePassword(@Valid @ModelAttribute(value = "password") CustomerPassword password, BindingResult bindingResult, Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
/**
* template *
*/
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Customer.changePassword).append(".").append(store.getStoreTemplate());
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Customer customer = null;
if (auth != null && request.isUserInRole("AUTH_CUSTOMER")) {
customer = customerFacade.getCustomerByUserName(auth.getName(), store);
}
if (customer == null) {
return "redirect:/" + Constants.SHOP_URI;
}
String currentPassword = password.getCurrentPassword();
BCryptPasswordEncoder encoder = (BCryptPasswordEncoder) passwordEncoder;
if (!encoder.matches(currentPassword, customer.getPassword())) {
FieldError error = new FieldError("password", "password", messages.getMessage("message.invalidpassword", locale));
bindingResult.addError(error);
}
if (bindingResult.hasErrors()) {
LOGGER.info("found {} validation error while validating customer password", bindingResult.getErrorCount());
return template.toString();
}
CustomerPassword customerPassword = new CustomerPassword();
model.addAttribute("password", customerPassword);
String newPassword = password.getPassword();
String encodedPassword = passwordEncoder.encode(newPassword);
customer.setPassword(encodedPassword);
customerService.saveOrUpdate(customer);
emailTemplatesUtils.changePasswordNotificationEmail(customer, store, LocaleUtils.getLocale(customer.getDefaultLanguage()), request.getContextPath());
model.addAttribute("success", "success");
return template.toString();
}
Aggregations