]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Mon, 29 Aug 2016 15:51:00 +0000 (17:51 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 29 Aug 2016 17:28:28 +0000 (19:28 +0200)
- added base URL parameter + email delivery

src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java

index 87ac502278d666021d00114eb72555848d04bc8b..a07eea9472e6b647567863684265b9e3520de154 100644 (file)
@@ -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