From 99f363e4d92c5e68eeb621c59fde99c62120df0e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 22 Jun 2017 22:55:38 +0200 Subject: [PATCH] Please cherry-pick: - moved EJBs to proper package as they are user-related beans - handled over randomPassword parameter to sendEmail() - or null if not possible/wanted MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../login/PizzaUserLoginSessionBean.java | 2 +- .../model/user/PizzaAdminUserSessionBean.java | 28 ++++++------- .../model/user/PizzaUserSessionBean.java | 40 +++++++++---------- .../PizzaUserEmailChangeSessionBean.java | 7 +++- .../PizzaUserRegistrationSessionBean.java | 10 +++-- .../PizzaResendLinkSessionBean.java | 6 +-- 6 files changed, 49 insertions(+), 44 deletions(-) rename src/java/org/mxchange/jusercore/model/{ => user}/email_address/PizzaUserEmailChangeSessionBean.java (95%) rename src/java/org/mxchange/jusercore/model/{ => user}/register/PizzaUserRegistrationSessionBean.java (92%) rename src/java/org/mxchange/{pizzaapplication/model => jusercore/model/user}/resendlink/PizzaResendLinkSessionBean.java (94%) diff --git a/src/java/org/mxchange/jusercore/model/login/PizzaUserLoginSessionBean.java b/src/java/org/mxchange/jusercore/model/login/PizzaUserLoginSessionBean.java index 84b2bcb..4a90a00 100644 --- a/src/java/org/mxchange/jusercore/model/login/PizzaUserLoginSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/login/PizzaUserLoginSessionBean.java @@ -24,7 +24,7 @@ import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; import org.mxchange.jusercore.exceptions.UserStatusLockedException; import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; -import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote; +import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.UserSessionBeanRemote; import org.mxchange.jusercore.model.user.UserUtils; diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java index dc7875f..68ac712 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java @@ -31,7 +31,7 @@ import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.exceptions.UserStatusConfirmedException; import org.mxchange.jusercore.exceptions.UserStatusLockedException; import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; -import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote; +import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote; import org.mxchange.jusercore.model.user.status.UserAccountStatus; import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean; @@ -144,13 +144,13 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements } // Get a managed instance - User managedUser = this.getManagedUser(user); + User updatedUser = this.getManagedUser(user); // Should be found! - assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N + assert (updatedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N // Delete it - this.getEntityManager().remove(managedUser); + this.getEntityManager().remove(updatedUser); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteUser: EXIT!", this.getClass().getSimpleName())); //NOI18N @@ -263,14 +263,14 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements user.setUserLastLockedReason(userLockReason); // Update user - User managedUser = this.userBean.updateUserData(user); + User updatedUser = this.userBean.updateUserData(user); // Init variable Address emailAddress; try { // Create email address and set - emailAddress = new InternetAddress(managedUser.getUserContact().getContactEmailAddress()); + emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress()); } catch (final AddressException ex) { // Throw again throw new EJBException(ex); @@ -278,13 +278,13 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements // Send out email // @TODO externalize subject line - this.sendEmail("Account locked", "account_locked", emailAddress, managedUser, baseUrl); //NOI18N + this.sendEmail("User account locked", "user_account_locked", emailAddress, updatedUser, baseUrl, null); //NOI18N // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N // Return detached (and updated) user - return managedUser; + return updatedUser; } @Override @@ -332,14 +332,14 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements user.setUserAccountStatus(UserAccountStatus.CONFIRMED); // Update user - User managedUser = this.userBean.updateUserData(user); + User updatedUser = this.userBean.updateUserData(user); // Init variable Address emailAddress; try { // Create email address and set - emailAddress = new InternetAddress(managedUser.getUserContact().getContactEmailAddress()); + emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress()); } catch (final AddressException ex) { // Throw again throw new EJBException(ex); @@ -347,13 +347,13 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements // Send out email // @TODO externalize subject line - this.sendEmail("Account unlocked", "account_unlocked", emailAddress, managedUser, baseUrl); //NOI18N + this.sendEmail("User Account unlocked", "user_account_unlocked", emailAddress, updatedUser, baseUrl, null); //NOI18N // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N // Return changed account - return managedUser; + return updatedUser; } } diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java index 8a859ad..8bee996 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java @@ -36,10 +36,10 @@ import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.exceptions.UserStatusConfirmedException; import org.mxchange.jusercore.exceptions.UserStatusLockedException; import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; -import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote; import org.mxchange.jusercore.model.user.password_history.PasswordHistory; import org.mxchange.jusercore.model.user.password_history.UserPasswordHistory; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; +import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote; import org.mxchange.jusercore.model.user.status.UserAccountStatus; import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean; @@ -188,7 +188,7 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } // Send out email - this.sendEmail("Account confirmed", "account_confirmed", emailAddress, updatedUser, baseUrl); //NOI18N + this.sendEmail("User account confirmed", "user_account_confirmed", emailAddress, updatedUser, baseUrl, null); //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N @@ -578,22 +578,22 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } // Find the instance - User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId()); + User updatedUser = this.getEntityManager().find(user.getClass(), user.getUserId()); // Should be found! - assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N + assert (updatedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N // Copy all data - managedUser.copyAll(user); + updatedUser.copyAll(user); // Set as updated - managedUser.setUserUpdated(new GregorianCalendar()); + updatedUser.setUserUpdated(new GregorianCalendar()); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N // Return updated instance - return managedUser; + return updatedUser; } @Override @@ -644,16 +644,16 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } // Call other method - User managedUser = this.updateUserData(user); + User updatedUser = this.updateUserData(user); // Create history entry - PasswordHistory entry = new UserPasswordHistory(managedUser.getUserEncryptedPassword(), managedUser); + PasswordHistory entry = new UserPasswordHistory(updatedUser.getUserEncryptedPassword(), updatedUser); // Set created timestamp entry.setUserPasswordHistoryCreated(new GregorianCalendar()); // Merge user to make sure it is not re-persisted - User mergedUser = this.getEntityManager().merge(managedUser); + User mergedUser = this.getEntityManager().merge(updatedUser); entry.setUserPasswordHistoryUser(mergedUser); // Persist it @@ -667,14 +667,14 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS try { // Create email address and set - emailAddress = new InternetAddress(managedUser.getUserContact().getContactEmailAddress()); + 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 + this.sendEmail("User password change", "user_password_change", emailAddress, updatedUser, baseUrl, null); //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: entry.userPasswordHistoryId={1} - EXIT!", this.getClass().getSimpleName(), entry.getUserPasswordHistoryId())); //NOI18N @@ -707,17 +707,17 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } // Find the instance - User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId()); + User updatedUser = this.getEntityManager().find(user.getClass(), user.getUserId()); // Should be found! - assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N + assert (updatedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N // Copy all data - managedUser.copyAll(user); + updatedUser.copyAll(user); // Set as updated - managedUser.setUserUpdated(new GregorianCalendar()); - managedUser.getUserContact().setContactUpdated(new GregorianCalendar()); + updatedUser.setUserUpdated(new GregorianCalendar()); + updatedUser.getUserContact().setContactUpdated(new GregorianCalendar()); // Get contact from it and find it Contact managedContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId()); @@ -774,10 +774,10 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS } // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPersonalData: entry.managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPersonalData: entry.updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N // Return updated user instance - return managedUser; + return updatedUser; } } diff --git a/src/java/org/mxchange/jusercore/model/email_address/PizzaUserEmailChangeSessionBean.java b/src/java/org/mxchange/jusercore/model/user/email_address/PizzaUserEmailChangeSessionBean.java similarity index 95% rename from src/java/org/mxchange/jusercore/model/email_address/PizzaUserEmailChangeSessionBean.java rename to src/java/org/mxchange/jusercore/model/user/email_address/PizzaUserEmailChangeSessionBean.java index 5e7024e..5c86853 100644 --- a/src/java/org/mxchange/jusercore/model/email_address/PizzaUserEmailChangeSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/email_address/PizzaUserEmailChangeSessionBean.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jusercore.model.email_address; +package org.mxchange.jusercore.model.user.email_address; import java.text.MessageFormat; import java.util.GregorianCalendar; @@ -27,6 +27,9 @@ import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.persistence.NoResultException; import javax.persistence.Query; +import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress; +import org.mxchange.jusercore.model.email_address.EmailAddressChange; +import org.mxchange.jusercore.model.email_address.UserEmailChangeSessionBeanRemote; import org.mxchange.jusercore.model.user.UserSessionBeanRemote; import org.mxchange.jusercore.model.user.UserUtils; import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean; @@ -127,7 +130,7 @@ public class PizzaUserEmailChangeSessionBean extends BasePizzaDatabaseBean imple } // Send email - this.sendEmail("Email change", "email_change", emailAddress, emailChange.getEmailChangeUser(), baseUrl); //NOI18N + this.sendEmail("User email change", "user_email_change", emailAddress, emailChange.getEmailChangeUser(), baseUrl, null); //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.enqueueEmailAddressForChange - EXIT!", this.getClass().getSimpleName())); //NOI18N diff --git a/src/java/org/mxchange/jusercore/model/register/PizzaUserRegistrationSessionBean.java b/src/java/org/mxchange/jusercore/model/user/register/PizzaUserRegistrationSessionBean.java similarity index 92% rename from src/java/org/mxchange/jusercore/model/register/PizzaUserRegistrationSessionBean.java rename to src/java/org/mxchange/jusercore/model/user/register/PizzaUserRegistrationSessionBean.java index f0a1d7c..c6c5704 100644 --- a/src/java/org/mxchange/jusercore/model/register/PizzaUserRegistrationSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/register/PizzaUserRegistrationSessionBean.java @@ -14,9 +14,10 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jusercore.model.register; +package org.mxchange.jusercore.model.user.register; import java.text.MessageFormat; +import java.util.Objects; import javax.ejb.EJB; import javax.ejb.EJBException; import javax.ejb.Stateless; @@ -28,6 +29,7 @@ import javax.persistence.Query; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException; +import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote; import org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; @@ -151,9 +153,9 @@ public class PizzaUserRegistrationSessionBean extends BasePizzaDatabaseBean impl } @Override - public User registerUser (final User user, final String baseUrl) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException { + public User registerUser (final User user, final String baseUrl, final String randomPassword) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.registerUser: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.registerUser: user={1},baseUrl={2},randomPassword[]={3} - CALLED!", this.getClass().getSimpleName(), user, baseUrl, Objects.toString(randomPassword))); //NOI18N // user should not be null if (null == user) { @@ -195,7 +197,7 @@ public class PizzaUserRegistrationSessionBean extends BasePizzaDatabaseBean impl // Send email // @TODO: Internationlize the subject line somehow - this.sendEmail("Registration", "registration", emailAddress, addedUser, baseUrl); //NOI18N + this.sendEmail("User registration", "user_registration", emailAddress, addedUser, baseUrl, randomPassword); //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.registerUser: addedUser={1},addedUser.userId={2} - EXIT!", this.getClass().getSimpleName(), addedUser, addedUser.getUserId())); //NOI18N diff --git a/src/java/org/mxchange/pizzaapplication/model/resendlink/PizzaResendLinkSessionBean.java b/src/java/org/mxchange/jusercore/model/user/resendlink/PizzaResendLinkSessionBean.java similarity index 94% rename from src/java/org/mxchange/pizzaapplication/model/resendlink/PizzaResendLinkSessionBean.java rename to src/java/org/mxchange/jusercore/model/user/resendlink/PizzaResendLinkSessionBean.java index bdb789e..ad2a82f 100644 --- a/src/java/org/mxchange/pizzaapplication/model/resendlink/PizzaResendLinkSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/resendlink/PizzaResendLinkSessionBean.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.pizzaapplication.model.resendlink; +package org.mxchange.jusercore.model.user.resendlink; import java.text.MessageFormat; import java.util.Locale; @@ -27,11 +27,11 @@ import javax.mail.internet.InternetAddress; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.exceptions.UserStatusConfirmedException; import org.mxchange.jusercore.exceptions.UserStatusLockedException; -import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote; import org.mxchange.jusercore.model.resendlink.ResendLinkSessionBeanRemote; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.UserSessionBeanRemote; +import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote; import org.mxchange.jusercore.model.user.status.UserAccountStatus; import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean; @@ -122,7 +122,7 @@ public class PizzaResendLinkSessionBean extends BasePizzaDatabaseBean implements // Send email // @TODO: Internationlize the subject line somehow - this.sendEmail("Resend confirmation link", "resend_confirmation_link", emailAddress, user, baseUrl); //NOI18N + this.sendEmail("Resend user confirmation link", "user_resend_confirmation_link", emailAddress, user, baseUrl, null); //NOI18N // Log trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.resendConfirmationLink: EXIT!", this.getClass().getSimpleName())); //NOI18N -- 2.39.5