From fc0001d08cd227107b736d9010f860128d0bb800 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 29 Aug 2016 17:51:00 +0200 Subject: [PATCH] Please cherry-pick: - added base URL parameter + email delivery --- .../model/user/JobsUserSessionBean.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java index d042455..bc46b1d 100644 --- a/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java @@ -158,6 +158,12 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes } 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 JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes } @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 JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes } 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 JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes // 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 -- 2.39.5