public String resetPassword() { String message = null; try { String currentPassword = changePasswordBean.getCurrentPassword(); String newPassword = changePasswordBean.getNewPassword(); String confirmPassword = changePasswordBean.getConfirmPassword(); User user = userBean.getUser(); if (currentPassword != null && currentPassword.equals(user.getPassword()) && newPassword.equals(confirmPassword)) { UserService userService = managerService.getUserService(); user.setPassword(newPassword); user.setcPassword(confirmPassword); user = userService.update(user); if (user != null) message = SUCCESS_MESSAGE_UPDATE; } else { message = ERROR_MESSAGE_UPDATE; } } catch (Exception exception) { message = ERROR_MESSAGE_EXCEPTION; logger.error(exception.getMessage()); } addMessageToFacesContext(message); return NO_REDIRECTION; }
public String sendPasswordViaEmail() { String message = null; try { String emailAddress = changePasswordBean.getEmailAddress(); if (emailAddress != null && emailAddress.length() > 0) { UserService userService = managerService.getUserService(); User user = userService.getUserByEmail(emailAddress); if (user != null) { EmailService emailService = managerService.getEmailService(); EmailBean forgotPasswordEmailBean = EmailBean.getForgotPasswordEmailBean(user.getEmailAddress(), user.getPassword()); emailService.sendMail(forgotPasswordEmailBean); message = SUCCESS_MESSAGE_SEND; } else { message = ERROR_MESSAGE_USER_INVALID; } } else { message = ERROR_MESSAGE_EMAIL_INVALID; } } catch (Exception exception) { message = ERROR_MESSAGE_EXCEPTION; logger.error(exception.getMessage()); } addMessageToFacesContext(message); return NO_REDIRECTION; }