From 60c4f7de9eaa325bd7fdbd63b69111227ab3a462 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 26 Apr 2016 17:57:13 +0200 Subject: [PATCH] Continued a lot more: - added ability to link any contact with user and/or customer accounts (later is unfinished) - to make thism working, a controller method selectableContacts() is needed (cached) - also the event for administrators adding users (customers missing!) must be observed to remove contact from selectable list - because of the above, the HTML form can no longer validate required="true", it must be done by the controller (ugly exceptions for now) - some beans/controllers loaded/injected - added missing i18n strings - fixed some exception messages - ignored strings for i18n - changed CSS class in admin area pages from small to medium (needs more space) - removed double underscore (one removed) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- nbproject/faces-config.NavData | 106 +++++++++--------- .../contact/JobsContactWebSessionBean.java | 6 +- .../user/JobsAdminUserWebRequestBean.java | 74 +++++++++--- .../beans/user/JobsUserWebSessionBean.java | 10 +- web/WEB-INF/faces-config.xml | 9 +- web/WEB-INF/templates/login/login_base.tpl | 6 - web/admin/user/admin_user_list.xhtml | 27 ++++- web/resources/css/cssLayout.css | 2 +- 8 files changed, 154 insertions(+), 86 deletions(-) diff --git a/nbproject/faces-config.NavData b/nbproject/faces-config.NavData index 145bb042..22905454 100644 --- a/nbproject/faces-config.NavData +++ b/nbproject/faces-config.NavData @@ -2,59 +2,63 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java index 1203e058..e9a8badf 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java @@ -237,13 +237,13 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle throw new NullPointerException("event is null"); //NOI18N } else if (event.getUpdatedContact() == null) { // Throw NPE again - throw new NullPointerException("event.user is null"); //NOI18N + throw new NullPointerException("event.updatedUser is null"); //NOI18N } else if (event.getUpdatedContact().getContactId() == null) { // userId is null - throw new NullPointerException("event.user.userId is null"); //NOI18N + throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N } else if (event.getUpdatedContact().getContactId() < 1) { // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N } // Get iterator from list diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java index b2c52c38..12fb8298 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java @@ -143,36 +143,78 @@ public class JobsAdminUserWebRequestBean implements JobsAdminUserWebRequestContr @Override public String addUser () { // Create new user instance - User localUser = new LoginUser(); + User user = new LoginUser(); + + // As the form cannot validate the data (required="true"), check it here + if (this.getUserName() == null) { + // Throw NPE + throw new NullPointerException("userName is null"); //NOI18N + } else if (this.getUserName().isEmpty()) { + // Is empty + throw new IllegalArgumentException("userName is null"); //NOI18N + } else if (this.adminHelper.getContact() == null) { + // No contact instance set, so test required fields: gender, first name and family name + if (this.contactController.getGender() == null) { + // Throw NPE again + throw new NullPointerException("contactController.gender is null"); //NOI18N + } else if (this.contactController.getFirstName() == null) { + // ... and again + throw new NullPointerException("contactController.firstName is null"); //NOI18N //NOI18N + } else if (this.contactController.getFirstName().isEmpty()) { + // ... and again + throw new IllegalArgumentException("contactController.firstName is empty"); + } else if (this.contactController.getFamilyName() == null) { + // ... and again + throw new NullPointerException("contactController.familyName is null"); //NOI18N + } else if (this.contactController.getFamilyName().isEmpty()) { + // ... and again + throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N //NOI18N + } else if (this.contactController.getEmailAddress()== null) { + // ... and again + throw new NullPointerException("contactController.emailAddress is null"); + } else if (this.contactController.getEmailAddress().isEmpty()) { + // ... and again + throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N //NOI18N + } else if (this.contactController.getEmailAddressRepeat()== null) { + // ... and again + throw new NullPointerException("contactController.emailAddressRepeat is null"); + } else if (this.contactController.getEmailAddressRepeat().isEmpty()) { + // ... and again + throw new IllegalArgumentException("contactController.emailAddressRepeat is empty"); //NOI18N //NOI18N + } else if (!Objects.equals(this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat())) { + // Is not same email address + throw new IllegalArgumentException("Both entered email addresses don't match."); + } + } // Set user name, CONFIRMED and INVISIBLE - localUser.setUserName(this.getUserName()); - localUser.setUserAccountStatus(UserAccountStatus.CONFIRMED); - localUser.setUserProfileMode(ProfileMode.INVISIBLE); + user.setUserName(this.getUserName()); + user.setUserAccountStatus(UserAccountStatus.CONFIRMED); + user.setUserProfileMode(ProfileMode.INVISIBLE); // Create contact instance Contact contact = this.contactController.createContactInstance(); // Set contact in user - localUser.setUserContact(contact); + user.setUserContact(contact); // Init variable for password String password = null; // Is the user name or email address used already? // @TODO Add password length check - if (this.userController.isUserNameRegistered(localUser)) { + if (this.userController.isUserNameRegistered(user)) { // User name is already used - throw new FaceletException(new UserNameAlreadyRegisteredException(localUser)); - } else if (this.contactController.isEmailAddressRegistered(localUser.getUserContact())) { + throw new FaceletException(new UserNameAlreadyRegisteredException(user)); + } else if ((this.adminHelper.getContact() == null) && (this.contactController.isEmailAddressRegistered(user.getUserContact()))) { // Email address is already used - throw new FaceletException(new EmailAddressAlreadyRegisteredException(localUser)); + throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); } else if ((this.getUserPassword() == null && (this.getUserPasswordRepeat() == null)) || ((this.getUserPassword().isEmpty()) && (this.getUserPasswordRepeat().isEmpty()))) { // Empty password entered, then generate one password = UserUtils.createRandomPassword(JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH); } else if (!this.isSamePasswordEntered()) { // Both passwords don't match - throw new FaceletException(new UserPasswordRepeatMismatchException(localUser)); + throw new FaceletException(new UserPasswordRepeatMismatchException(user)); } else { // Both match, so get it from this bean password = this.getUserPassword(); @@ -183,15 +225,21 @@ public class JobsAdminUserWebRequestBean implements JobsAdminUserWebRequestContr assert (password.length() >= JobsUserWebSessionController.MINIMUM_PASSWORD_LENGTH) : "Password is not long enough."; //NOI18N // Encrypt password and set it - localUser.setUserEncryptedPassword(UserUtils.encryptPassword(password)); + user.setUserEncryptedPassword(UserUtils.encryptPassword(password)); // Init updated user instance User updatedUser = null; try { // Now, that all is set, call EJB - updatedUser = this.userBean.addUser(localUser); - } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) { + if (this.adminHelper.getContact() instanceof Contact) { + // Link contact with this user + updatedUser = this.userBean.linkUser(user); + } else { + // Add new contact + updatedUser = this.userBean.addUser(user); + } + } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) { // Throw again throw new FaceletException(ex); } diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java index d5ab4926..21bbde26 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java @@ -142,7 +142,7 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController { @Override public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) { // Trace message - System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N // event should not be null if (null == event) { @@ -163,7 +163,7 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController { User registeredUser = event.getRegisteredUser(); // Debug message - System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N // Copy all data from registered->user this.copyUser(registeredUser); @@ -184,13 +184,13 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController { } // Trace message - System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N } @Override public void afterUserLogin (final @Observes UserLoggedInEvent event) { // Trace message - System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N // event should not be null if (null == event) { @@ -214,7 +214,7 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController { this.copyUser(event.getLoggedInUser()); // Trace message - System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N } @Override diff --git a/web/WEB-INF/faces-config.xml b/web/WEB-INF/faces-config.xml index 988756c8..0d74bfab 100644 --- a/web/WEB-INF/faces-config.xml +++ b/web/WEB-INF/faces-config.xml @@ -100,20 +100,17 @@ -<<<<<<< HEAD -======= - /user/login.xhtml + /guest/user/login.xhtml login - /login/login_index.xhtml + /user/login_index.xhtml login_index - /login/index.xhtml + /user/index.xhtml ->>>>>>> 8eb0fb9... added initial login templates and navigation rules /user/register.xhtml register_done diff --git a/web/WEB-INF/templates/login/login_base.tpl b/web/WEB-INF/templates/login/login_base.tpl index 0a2d405d..dafc7786 100644 --- a/web/WEB-INF/templates/login/login_base.tpl +++ b/web/WEB-INF/templates/login/login_base.tpl @@ -2,7 +2,6 @@ @@ -20,9 +19,4 @@ -======= - xmlns:ui="http://java.sun.com/jsf/facelets"> - - Benutzerbereich - ->>>>>>> b5abdb2... added initial login templates and navigation rules diff --git a/web/admin/user/admin_user_list.xhtml b/web/admin/user/admin_user_list.xhtml index de997601..c0168f1d 100644 --- a/web/admin/user/admin_user_list.xhtml +++ b/web/admin/user/admin_user_list.xhtml @@ -70,12 +70,37 @@ -
+
#{msg.ADMIN_ADD_USER_TITLE}
+
+
+ #{msg.ADMIN_SELECT_USER_CONTACT_LEGEND} + +
+
+ +
+ +
+ + + + +
+ +
+
+
+
+ +
+ +
+