X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Faddressbook%2Fbeans%2Fuser%2FAddressbookUserWebSessionBean.java;h=be477ac84efbc855b8b75db95ef8c827120d05f2;hb=28b1fd4a8d4809b3c5cc439efebe0ed31bbbb95b;hp=411f08234ab07bc68bcbb722fbfca12a95b430d7;hpb=54b06252c57dee50394e142fab8ba3161c4f6c38;p=addressbook-war.git diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java index 411f0823..be477ac8 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java @@ -26,14 +26,17 @@ import javax.enterprise.context.SessionScoped; import javax.enterprise.event.Event; import javax.enterprise.event.Observes; import javax.enterprise.inject.Any; +import javax.faces.context.FacesContext; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; +import org.mxchange.addressbook.beans.BaseAddressbookController; import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController; import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController; +import org.mxchange.addressbook.beans.register.AddressbookUserRegisterWebSessionController; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; @@ -48,6 +51,7 @@ import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; 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.profilemodes.ProfileMode; /** @@ -57,7 +61,7 @@ import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; */ @Named ("userController") @SessionScoped -public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionController { +public class AddressbookUserWebSessionBean extends BaseAddressbookController implements AddressbookUserWebSessionController { /** * Serial number @@ -81,6 +85,12 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC @Inject private AddressbookUserLoginWebSessionController loginController; + /** + * Registration controller + */ + @Inject + private AddressbookUserRegisterWebSessionController registerController; + /** * A list of all selectable contacts */ @@ -157,7 +167,7 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC this.userBean = (UserSessionBeanRemote) context.lookup("java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N // Try to lookup - this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N + this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N } catch (final NamingException e) { // Throw again throw new FaceletException(e); @@ -170,7 +180,7 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedContact()== null) { + } else if (event.getAddedContact() == null) { // Throw again ... throw new NullPointerException("event.addedContact is null"); //NOI18N } else if (event.getAddedContact().getContactId() == null) { @@ -370,26 +380,46 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N // Create new user instance - User localUser = new LoginUser(); + User user = new LoginUser(); - // Update all data ... - localUser.setUserName(this.getUserName()); - localUser.setUserProfileMode(this.getUserProfileMode()); + // Is user name required? + if (!this.isUserNameRequired()) { + // Generate pseudo-random user name + String randomName = this.userBean.generateRandomUserName(); - // Create contact instance - Contact contact = this.contactController.createContactInstance(); + // Set it and inivisible profile + this.setUserName(randomName); + this.setUserProfileMode(ProfileMode.INVISIBLE); - // Debug message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: contact={1}", this.getClass().getSimpleName(), contact)); + // Generate random password + String randomPassword = UserUtils.createRandomPassword(AddressbookUserWebSessionController.MINIMUM_PASSWORD_LENGTH); + + // Set random password + this.setUserPassword(randomPassword); + this.setUserPasswordRepeat(randomPassword); + } + + // Set user name and mode + user.setUserName(this.getUserName()); + user.setUserProfileMode(this.getUserProfileMode()); + + // Is multiple registration page + if (!this.registerController.isMultiplePageEnabled()) { + // Create contact instance + Contact contact = this.contactController.createContactInstance(); - // Set contact in user - localUser.setUserContact(contact); + // Debug message + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: contact={1}", this.getClass().getSimpleName(), contact)); + + // Set contact in user + user.setUserContact(contact); + } // Trace message //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: user={1} - EXIT!", this.getClass().getSimpleName(), user)); // Return it - return localUser; + return user; } @Override @@ -607,6 +637,24 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC return isFound; } + @Override + public boolean isPublicUserProfileEnabled () { + // Get context parameter + String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_public_profile_enabled"); //NOI18N + + // Is it set? + boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N + + // This requires user names being enabled, too. + if ((isEnabled) && (!this.isUserNameRequired())) { + // Not valid state, users must be able to modify their profile, especially when it is public + throw new IllegalStateException("Public user profiles are enabled but user name requirement is disabled, this is not possible."); //NOI18N + } + + // Return value + return isEnabled; + } + @Override public boolean isRequiredChangePersonalDataSet () { return ((this.getUserProfileMode() != null) && @@ -616,11 +664,17 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC @Override public boolean isRequiredPersonalDataSet () { - return ((this.getUserName() != null) && - (this.getUserProfileMode() != null) && - (this.contactController.isRequiredPersonalDataSet()) && - (this.getUserPassword() != null) && - (this.getUserPasswordRepeat() != null)); + if (this.registerController.isMultiplePageEnabled()) { + // Multiple registration page + return this.contactController.isRequiredPersonalDataSet(); + } else { + // Single registration page + return (((this.getUserName() != null) || (!this.isUserNameRequired())) && + (this.getUserProfileMode() != null) && + (this.contactController.isRequiredPersonalDataSet()) && + (this.getUserPassword() != null) && + (this.getUserPasswordRepeat() != null)); + } } @Override @@ -638,6 +692,18 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName()))); } + @Override + public boolean isUserNameRequired () { + // Get context parameter + String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_user_name_required"); //NOI18N + + // Is it set? + boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N + + // Return value + return isRequired; + } + @Override public boolean isVisibleUserFound () { return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));