X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fjjobs%2Fbeans%2Fuser%2Fregister%2FJobsUserRegisterWebSessionBean.java;h=f1dd0182319f5b0431e9d6718c299ac84318c39f;hb=d4e4a6180bb781834c1173b485a20978383617d2;hp=f8fbe58f48a2f330c020e570f0c0e9d3606a3d39;hpb=02357a08678aaaeb18cb9fe4154c77ed8c865940;p=jjobs-war.git diff --git a/src/java/org/mxchange/jjobs/beans/user/register/JobsUserRegisterWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/register/JobsUserRegisterWebSessionBean.java index f8fbe58f..f1dd0182 100644 --- a/src/java/org/mxchange/jjobs/beans/user/register/JobsUserRegisterWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/register/JobsUserRegisterWebSessionBean.java @@ -16,7 +16,6 @@ */ package org.mxchange.jjobs.beans.user.register; -import java.text.MessageFormat; import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.enterprise.event.Event; @@ -35,15 +34,23 @@ import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController; import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController; import org.mxchange.jjobs.beans.user.JobsAdminUserWebRequestController; import org.mxchange.jjobs.beans.user.JobsUserWebSessionController; -import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent; -import org.mxchange.jusercore.events.registration.UserRegisteredEvent; +import org.mxchange.jusercore.events.user.clear.password.ClearUserPasswordEvent; +import org.mxchange.jusercore.events.user.clear.password.ObservableClearUserPasswordEvent; +import org.mxchange.jusercore.events.user.clear.username.ClearUserNameEvent; +import org.mxchange.jusercore.events.user.clear.username.ObservableClearUserNameEvent; import org.mxchange.jusercore.exceptions.DataRepeatMismatchException; import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException; import org.mxchange.jusercore.model.user.User; -import org.mxchange.jusercore.model.user.UserUtils; -import org.mxchange.jusercore.model.user.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.status.UserAccountStatus; +import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent; +import org.mxchange.juserlogincore.events.registration.UserRegisteredEvent; +import org.mxchange.juserlogincore.events.user.password_change.ObservableUpdatedUserPasswordEvent; +import org.mxchange.juserlogincore.events.user.password_change.UpdatedUserPasswordEvent; +import org.mxchange.juserlogincore.login.UserLoginUtils; +import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote; /** * A web bean for user registration @@ -89,7 +96,28 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement private JobsUserWebSessionController userController; /** - * An en event fireable when a new user has registered + * An event being fired when a user password was changed + */ + @Inject + @Any + private Event userPasswordChangedEvent; + + /** + * An event being fired when a user name should be cleared + */ + @Inject + @Any + private Event clearUserNameEvent; + + /** + * An event being fired when a user password should be cleared + */ + @Inject + @Any + private Event clearUserPasswordEvent; + + /** + * An event being fired when a new user has registered */ @Inject @Any @@ -103,7 +131,12 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement super(); } - @Override + /** + * Registers the user, if not found. Otherwise this method should throw an + * exception. + *

+ * @return Redirection target + */ public String doFinishRegistration () { // Is registration enabled? if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N @@ -124,14 +157,16 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement } else if (!this.userController.isRequiredPersonalDataSet()) { // Not all required fields are set throw new FaceletException("Not all required fields are set."); //NOI18N - } else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N + } else if ((this.featureController.isFeatureEnabled("user_login_require_user_name")) && (this.userController.isUserNameRegistered(user))) { //NOI18N // Is multi-page enabled? if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N // User name is already used, should not happen here throw new FaceletException(new UserNameAlreadyRegisteredException(user)); } else { - // May happen here, reset field - this.userController.setUserName(null); + // May happen here, fire event + this.clearUserNameEvent.fire(new ClearUserNameEvent()); + + // Output message this.showFacesMessage("form_register_single:userName", "ERROR_USER_NAME_ALREADY_USED"); //NOI18N return ""; //NOI18N } @@ -142,8 +177,7 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); } else { // May happen here, reset fields - this.contactController.setEmailAddress(null); - this.contactController.setEmailAddressRepeat(null); + this.contactController.clearEmailAddresses(); this.showFacesMessage("form_register_single:emailAddressRepeat", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N return ""; //NOI18N } @@ -151,11 +185,10 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement // Is multi-page enabled? if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N // Not same email address entered, should not happen here - throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N + throw new FaceletException(new DataRepeatMismatchException("Email addresses not matching.")); //NOI18N } else { // May happen here, reset fields - this.contactController.setEmailAddress(null); - this.contactController.setEmailAddressRepeat(null); + this.contactController.clearEmailAddresses(); this.showFacesMessage("form_register_single:emailAddressRepeat", "ERROR_EMAIL_ADDRESSES_MISMATCHING"); //NOI18N return ""; //NOI18N } @@ -166,16 +199,18 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement throw new FaceletException(new DataRepeatMismatchException("Passwords not matching.")); //NOI18N } else if (this.userController.ifBothPasswordsEmptyAllowed()) { // Both passwords are left empty and is allowed, then generate a random password - randomPassword = UserUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH); + randomPassword = UserLoginUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH); - // Set it in both fields - this.userController.setUserPassword(randomPassword); - this.userController.setUserPasswordRepeat(randomPassword); + // Generate (ignored) password-history + PasswordHistory passwordHistory = new UserPasswordHistory(randomPassword, user); + + // Fire event + this.userPasswordChangedEvent.fire(new UpdatedUserPasswordEvent(passwordHistory, randomPassword)); } } // Encrypt password - String encryptedPassword = UserUtils.encryptPassword(this.userController.getUserPassword()); + String encryptedPassword = UserLoginUtils.encryptPassword(this.userController.getUserPassword()); // Set it here user.setUserEncryptedPassword(encryptedPassword); @@ -216,7 +251,13 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement } } - @Override + /** + * Handles registration request send from first page. The (maybe) entered + * user name and email address is not used and that privacy and T&C are + * accepted. + *

+ * @return Redirect + */ public String doRegisterMultiPage1 () { // Is registration enabled? if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N @@ -231,23 +272,23 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement if (null == user) { // user must be set throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N - } else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N + } else if ((this.featureController.isFeatureEnabled("user_login_require_user_name")) && (this.userController.isUserNameRegistered(user))) { //NOI18N // User name is already used, so clear it - this.userController.setUserName(null); + this.clearUserNameEvent.fire(new ClearUserNameEvent()); + + // Output message this.showFacesMessage("form_register_page1:userName", "ERROR_USER_NAME_ALREADY_USED"); //NOI18N return ""; //NOI18N } else if (!this.contactController.isSameEmailAddressEntered()) { // Not same email address entered, clear both - this.contactController.setEmailAddress(null); - this.contactController.setEmailAddressRepeat(null); + this.contactController.clearEmailAddresses(); this.showFacesMessage("form_register_page1:emailAddressRepeat", "ERROR_EMAIL_ADDRESSES_MISMATCHING"); //NOI18N return ""; //NOI18N } else if (!this.userController.isSamePasswordEntered()) { // Is multi-page enabled? if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N // Unset both - this.userController.setUserPassword(null); - this.userController.setUserPasswordRepeat(null); + this.clearUserPasswordEvent.fire(new ClearUserPasswordEvent()); // Output faces message this.showFacesMessage("form_register_page1:userPassword", "ERROR_USER_PASSWORD_EMPTY"); //NOI18N @@ -255,11 +296,13 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement return ""; //NOI18N } else if (this.userController.ifBothPasswordsEmptyAllowed()) { // Both passwords are left empty and is allowed, then generate a random password - String randomPassword = UserUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH); + String randomPassword = UserLoginUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH); + + // Generate (ignored) password-history + PasswordHistory passwordHistory = new UserPasswordHistory(randomPassword, user); - // Set it in both fields - this.userController.setUserPassword(randomPassword); - this.userController.setUserPasswordRepeat(randomPassword); + // Fire event + this.userPasswordChangedEvent.fire(new UpdatedUserPasswordEvent(passwordHistory, randomPassword)); } } @@ -273,14 +316,13 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement // Check if email address is registered if (this.contactController.isEmailAddressRegistered(user.getUserContact())) { // Email address has already been taken, clear both - this.contactController.setEmailAddress(null); - this.contactController.setEmailAddressRepeat(null); + this.contactController.clearEmailAddresses(); this.showFacesMessage("form_register_page1:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N return ""; //NOI18N } // Now only redirect to next page as the JSF does it - return "register_page2"; //NOI18N + return "user_register_page2"; //NOI18N } /** @@ -293,7 +335,7 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement Context context = new InitialContext(); // Try to lookup - this.registerBean = (UserRegistrationSessionBeanRemote) context.lookup("java:global/jjobs-ejb/register!org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote"); //NOI18N + this.registerBean = (UserRegistrationSessionBeanRemote) context.lookup("java:global/jjobs-ejb/userRegistration!org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote"); //NOI18N } catch (final NamingException ex) { // Continue to throw throw new FaceletException(ex);