From 7da12f683ca4950026d56c8619025dad44e63420 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/FinancialsUserLoginSessionBean.java | 2 +- .../user/FinancialsAdminUserSessionBean.java | 6 +++--- .../model/user/FinancialsUserSessionBean.java | 6 +++--- .../FinancialsUserEmailChangeSessionBean.java | 7 +++++-- ...FinancialsUserRegistrationSessionBean.java | 21 ++++++++++++++----- .../FinancialsResendLinkSessionBean.java | 8 +++---- 6 files changed, 32 insertions(+), 18 deletions(-) rename src/java/org/mxchange/jusercore/model/{ => user}/email_address/FinancialsUserEmailChangeSessionBean.java (95%) rename src/java/org/mxchange/jusercore/model/{ => user}/register/FinancialsUserRegistrationSessionBean.java (88%) rename src/java/org/mxchange/{jfinancials/beans => jusercore/model/user}/resendlink/FinancialsResendLinkSessionBean.java (93%) diff --git a/src/java/org/mxchange/jusercore/model/login/FinancialsUserLoginSessionBean.java b/src/java/org/mxchange/jusercore/model/login/FinancialsUserLoginSessionBean.java index ab18289..be464cb 100644 --- a/src/java/org/mxchange/jusercore/model/login/FinancialsUserLoginSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/login/FinancialsUserLoginSessionBean.java @@ -25,7 +25,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/FinancialsAdminUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/FinancialsAdminUserSessionBean.java index f20b64c..5ec021e 100644 --- a/src/java/org/mxchange/jusercore/model/user/FinancialsAdminUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/FinancialsAdminUserSessionBean.java @@ -32,7 +32,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; /** @@ -276,7 +276,7 @@ public class FinancialsAdminUserSessionBean extends BaseFinancialsDatabaseBean i // Send out email // @TODO externalize subject line - this.sendEmail("Account locked", "account_locked", emailAddress, updatedUser, baseUrl); //NOI18N + this.sendEmail("User account locked", "user_account_locked", emailAddress, updatedUser, baseUrl, null); //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N @@ -346,7 +346,7 @@ public class FinancialsAdminUserSessionBean extends BaseFinancialsDatabaseBean i // Send out email // @TODO externalize subject line - this.sendEmail("Account unlocked", "account_unlocked", emailAddress, updatedUser, baseUrl); //NOI18N + this.sendEmail("User account unlocked", "user_account_unlocked", emailAddress, updatedUser, baseUrl, null); //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N diff --git a/src/java/org/mxchange/jusercore/model/user/FinancialsUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/FinancialsUserSessionBean.java index d4c7c35..2da8f20 100644 --- a/src/java/org/mxchange/jusercore/model/user/FinancialsUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/FinancialsUserSessionBean.java @@ -28,8 +28,8 @@ import javax.mail.internet.InternetAddress; import javax.persistence.NoResultException; import javax.persistence.PersistenceException; import javax.persistence.Query; -import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean; import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; @@ -37,10 +37,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; /** @@ -182,7 +182,7 @@ public class FinancialsUserSessionBean extends BaseFinancialsDatabaseBean implem } // 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 diff --git a/src/java/org/mxchange/jusercore/model/email_address/FinancialsUserEmailChangeSessionBean.java b/src/java/org/mxchange/jusercore/model/user/email_address/FinancialsUserEmailChangeSessionBean.java similarity index 95% rename from src/java/org/mxchange/jusercore/model/email_address/FinancialsUserEmailChangeSessionBean.java rename to src/java/org/mxchange/jusercore/model/user/email_address/FinancialsUserEmailChangeSessionBean.java index 002509c..729f291 100644 --- a/src/java/org/mxchange/jusercore/model/email_address/FinancialsUserEmailChangeSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/email_address/FinancialsUserEmailChangeSessionBean.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; @@ -28,6 +28,9 @@ import javax.mail.internet.InternetAddress; import javax.persistence.NoResultException; import javax.persistence.Query; import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean; +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; @@ -124,7 +127,7 @@ public class FinancialsUserEmailChangeSessionBean extends BaseFinancialsDatabase } // 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/FinancialsUserRegistrationSessionBean.java b/src/java/org/mxchange/jusercore/model/user/register/FinancialsUserRegistrationSessionBean.java similarity index 88% rename from src/java/org/mxchange/jusercore/model/register/FinancialsUserRegistrationSessionBean.java rename to src/java/org/mxchange/jusercore/model/user/register/FinancialsUserRegistrationSessionBean.java index 32cf506..d818229 100644 --- a/src/java/org/mxchange/jusercore/model/register/FinancialsUserRegistrationSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/register/FinancialsUserRegistrationSessionBean.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; @@ -25,8 +26,8 @@ import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.persistence.NoResultException; import javax.persistence.Query; -import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean; import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean; import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException; import org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote; @@ -34,6 +35,7 @@ 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.UserUtils; +import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote; /** * A session-scoped bean for user registration @@ -151,9 +153,9 @@ public class FinancialsUserRegistrationSessionBean extends BaseFinancialsDatabas } @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) { @@ -193,9 +195,18 @@ public class FinancialsUserRegistrationSessionBean extends BaseFinancialsDatabas throw new EJBException(ex); } + // Default template is with no random password + String templateName = "user_registration"; //NOI18N + + // Is password set? + if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) { + // Switch to other template + templateName = "user_registration_random"; //NOI18N + } + // Send email // @TODO: Internationlize the subject line somehow - this.sendEmail("Registration", "registration", emailAddress, addedUser, baseUrl); //NOI18N + this.sendEmail("Registration", templateName, 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/jfinancials/beans/resendlink/FinancialsResendLinkSessionBean.java b/src/java/org/mxchange/jusercore/model/user/resendlink/FinancialsResendLinkSessionBean.java similarity index 93% rename from src/java/org/mxchange/jfinancials/beans/resendlink/FinancialsResendLinkSessionBean.java rename to src/java/org/mxchange/jusercore/model/user/resendlink/FinancialsResendLinkSessionBean.java index 4c94bc3..7c12c14 100644 --- a/src/java/org/mxchange/jfinancials/beans/resendlink/FinancialsResendLinkSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/resendlink/FinancialsResendLinkSessionBean.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.jfinancials.beans.resendlink; +package org.mxchange.jusercore.model.user.resendlink; import java.text.MessageFormat; import java.util.Locale; @@ -28,11 +28,11 @@ import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean; 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; /** @@ -69,7 +69,7 @@ public class FinancialsResendLinkSessionBean extends BaseFinancialsDatabaseBean } @Override - public void resendConfirmationLink (final User user, final Locale locale, final String baseUrl) throws UserNotFoundException, UserStatusLockedException, UserStatusConfirmedException { + public void resendConfirmationLink (final User user, final Locale locale, final String baseUrl) throws UserNotFoundException, UserStatusConfirmedException, UserStatusLockedException { // Log trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.resendConfirmationLink: user={1},locale={2},baseUrl={3} - CALLED!", this.getClass().getSimpleName(), user, locale, baseUrl)); //NOI18N @@ -122,7 +122,7 @@ public class FinancialsResendLinkSessionBean extends BaseFinancialsDatabaseBean // 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