From 0c0a20fc5b4f5def26035418e77008ff3874db2b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 13 May 2016 10:36:02 +0200 Subject: [PATCH] Fix for multi-page registration: - a contact instance is needed to check for email address as it is stored there - so first create a "half" contact instance (no gender, ...) and then check email address - user name can be only checked, if required MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsUserRegisterWebSessionBean.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java index d37f2aac..cf15f44f 100644 --- a/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java @@ -27,6 +27,8 @@ import javax.inject.Named; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; +import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.contact.UserContact; import org.mxchange.jjobs.beans.BaseJobsController; import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController; import org.mxchange.jjobs.beans.user.JobsAdminUserWebRequestController; @@ -165,21 +167,31 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement // Get user instance User user = this.userController.createUserInstance(); - // Page 1 has only email address and maybe user name + // First check if user is not null and user name is not used + if same email address is entered if (null == user) { // user must be set throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N } else if ((this.userController.isUserNameRequired()) && (this.userController.isUserNameRegistered(user))) { // User name is already used throw new FaceletException(new UserNameAlreadyRegisteredException(user)); - } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) { - // Email address has already been taken - throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); } else if (!this.contactController.isSameEmailAddressEntered()) { // Not same email address entered throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N } + // Create half contact instance with email address + Contact contact = new UserContact(); + contact.setContactEmailAddress(this.contactController.getEmailAddress()); + + // Set contact in user + user.setUserContact(contact); + + // Check if email address is registered + if (this.contactController.isEmailAddressRegistered(user.getUserContact())) { + // Email address has already been taken + throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); + } + // Now only redirect to next page as the JSF does it return "register_page2"; //NOI18N } -- 2.39.5