From: Roland Haeder Date: Tue, 6 Oct 2015 13:39:07 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4df058c7af042c6d536d0d995aa2f9957b14cc33;p=addressbook-war.git Continued: - new exception caught and renamed one - updated jars Signed-off-by:Roland Häder --- diff --git a/lib/jcontacts-core.jar b/lib/jcontacts-core.jar index 5fd68dc8..ceeaa29a 100644 Binary files a/lib/jcontacts-core.jar and b/lib/jcontacts-core.jar differ diff --git a/lib/juser-core.jar b/lib/juser-core.jar index 30c2eb82..bacd4604 100644 Binary files a/lib/juser-core.jar and b/lib/juser-core.jar differ diff --git a/lib/juser-lib.jar b/lib/juser-lib.jar index 83cf0fea..bc0d93d9 100644 Binary files a/lib/juser-lib.jar and b/lib/juser-lib.jar differ diff --git a/src/java/org/mxchange/addressbook/beans/register/UserRegisterWebBean.java b/src/java/org/mxchange/addressbook/beans/register/UserRegisterWebBean.java index 77cfa372..24dddcb4 100644 --- a/src/java/org/mxchange/addressbook/beans/register/UserRegisterWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/register/UserRegisterWebBean.java @@ -24,7 +24,8 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.addressbook.beans.user.UserWebController; -import org.mxchange.jusercore.exceptions.UserAlreadyRegisteredException; +import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; +import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException; import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.status.UserAccountStatus; @@ -75,6 +76,15 @@ public class UserRegisterWebBean implements UserRegisterWebController { // Get user instance User user = this.userController.createUserInstance(); + // Is the user already used? + if (this.userController.isUserNameRegistered(user.getUserName())) { + // User name is already used + throw new FaceletException(new UserNameAlreadyRegisteredException(user)); + } else if (this.userController.isEmailAddressRegistered(user.getUserContact().getEmailAddress())) { + // Email address has already been taken + throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); + } + // For debugging/programming only: user.setUserAccountStatus(UserAccountStatus.CONFIRMED); @@ -87,7 +97,7 @@ public class UserRegisterWebBean implements UserRegisterWebController { // All fine, redirect to proper page return "register_done"; //NOI18N - } catch (final UserAlreadyRegisteredException ex) { + } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) { // Continue to throw throw new FaceletException(ex); } diff --git a/src/java/org/mxchange/addressbook/beans/user/UserWebBean.java b/src/java/org/mxchange/addressbook/beans/user/UserWebBean.java index 5b0bdc27..de5c6e05 100644 --- a/src/java/org/mxchange/addressbook/beans/user/UserWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/UserWebBean.java @@ -17,6 +17,8 @@ package org.mxchange.addressbook.beans.user; import java.util.Date; +import java.util.List; +import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.faces.view.facelets.FaceletException; import javax.inject.Named; @@ -45,7 +47,6 @@ public class UserWebBean implements UserWebController { private static final long serialVersionUID = 542_145_347_916L; /////////////////////// Properties ///////////////////// - /** * Birth day */ @@ -136,6 +137,16 @@ public class UserWebBean implements UserWebController { */ private Integer zipCode; + /** + * Email address list + */ + private List emailAddressList; + + /** + * User name list + */ + private List userNameList; + /** * Default constructor */ @@ -156,6 +167,25 @@ public class UserWebBean implements UserWebController { } } + @Override + public boolean isEmailAddressRegistered (String emailAddress) { + return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(emailAddress))); + } + + @Override + public boolean isUserNameRegistered (final String userName) { + return ((this.userNameList instanceof List) && (this.userNameList.contains(userName))); + } + + @PostConstruct + public void init () { + // Get full user name list for reducing EJB calls + this.userNameList = this.userBean.getUserNameList(); + + // Get full email address list for reducing EJB calls + this.emailAddressList = this.userBean.getEmailAddressList(); + } + @Override public void copyUser (final User user) { // Copy all fields: @@ -216,7 +246,7 @@ public class UserWebBean implements UserWebController { @Override public Date getBirthday () { - return birthday; + return this.birthday; } @Override diff --git a/src/java/org/mxchange/addressbook/beans/user/UserWebController.java b/src/java/org/mxchange/addressbook/beans/user/UserWebController.java index 7bef48a4..cc7c9d16 100644 --- a/src/java/org/mxchange/addressbook/beans/user/UserWebController.java +++ b/src/java/org/mxchange/addressbook/beans/user/UserWebController.java @@ -42,6 +42,22 @@ public interface UserWebController extends Serializable { */ public User createUserInstance (); + /** + * Checks whether given user name is used + *

+ * @param userName User name to check + * @return Whether it is already used + */ + public boolean isUserNameRegistered (final String userName); + + /** + * Checks whether given email address is used + *

+ * @param emailAddress Email address to check + * @return Whether it is already used + */ + public boolean isEmailAddressRegistered (final String emailAddress); + /** * Getter for birth day *