public void changePassword(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String oldPassword = actionRequest.getParameter("oldPassword");
String newPassword = actionRequest.getParameter("newPassword");
String confirmPassword = actionRequest.getParameter("confirmPassword");
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
User user = themeDisplay.getUser();
String email = user.getEmailAddress();
boolean sendMail = false;
try {
RegCustomer regCustomer = RegCustomerLocalServiceUtil.getRegCustomer(email);
if(regCustomer.getPassword().equals(oldPassword)){
regCustomer.setPassword(newPassword);
UserServiceUtil.updatePassword(user.getUserId(), newPassword, confirmPassword, false);
regCustomer = RegCustomerLocalServiceUtil.updateRegCustomer(regCustomer);
sendMail = true;
}
else if(!regCustomer.getPassword().equals(oldPassword)){
SessionMessages.add(actionRequest, "request_processed", "Wrong Old Password");
}
} catch (Exception e) {
try {
BusinessUser businessUser = BusinessUserLocalServiceUtil.getBusinessUser(email);
if(businessUser.getPassword().equals(oldPassword)){
businessUser.setPassword(newPassword);
UserServiceUtil.updatePassword(user.getUserId(), newPassword, confirmPassword, false);
BusinessUserLocalServiceUtil.updateBusinessUser(businessUser);
sendMail = true;
}
else if(!businessUser.getPassword().equals(oldPassword)){
SessionMessages.add(actionRequest, "request_processed", "Wrong Old Password");
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
No comments:
Post a Comment