From: Roland Häder Date: Mon, 29 Aug 2016 15:51:00 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d16cd8ca780d2844e1861a1c316348538e1b185b;p=pizzaservice-ejb.git Please cherry-pick: - added base URL parameter + email delivery --- diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java index 87ac502..a07eea9 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java @@ -158,6 +158,12 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } else if (user.getUserConfirmKey() == null) { // Throw NPE throw new NullPointerException("user.userConfirmKey is null"); //NOI18N + } else if (null == baseUrl) { + // Throw it again + throw new NullPointerException("baseUrl is null"); //NOI18N + } else if (baseUrl.isEmpty()) { + // Invalid parameter + throw new IllegalArgumentException("baseUrl is empty"); //NOI18N } // Update user status and remove confirmation key @@ -592,9 +598,9 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } @Override - public PasswordHistory updateUserPassword (final User user) throws UserNotFoundException, UserStatusUnconfirmedException, UserStatusLockedException { + public PasswordHistory updateUserPassword (final User user, final String baseUrl) throws UserNotFoundException, UserStatusUnconfirmedException, UserStatusLockedException { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N // user should not be null if (null == user) { @@ -612,6 +618,12 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } else if (!this.ifUserExists(user)) { // User does not exist throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N + } else if (null == baseUrl) { + // Throw it again + throw new NullPointerException("baseUrl is null"); //NOI18N + } else if (baseUrl.isEmpty()) { + // Invalid parameter + throw new IllegalArgumentException("baseUrl is empty"); //NOI18N } // Call other method @@ -629,6 +641,20 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS // Flush it to get id number back this.getEntityManager().flush(); + // Init variable + Address emailAddress; + + try { + // Create email address and set + emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress()); + } catch (final AddressException ex) { + // Throw again + throw new EJBException(ex); + } + + // Send email to user + this.sendEmail("User password change", "user_password_change", emailAddress, user, baseUrl); //NOI18N + // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: entry.userPasswordHistoryId={1} - EXIT!", this.getClass().getSimpleName(), entry.getUserPasswordHistoryId())); //NOI18N