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;
// 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);
// 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);
}
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;
private static final long serialVersionUID = 542_145_347_916L;
/////////////////////// Properties /////////////////////
-
/**
* Birth day
*/
*/
private Integer zipCode;
+ /**
+ * Email address list
+ */
+ private List<String> emailAddressList;
+
+ /**
+ * User name list
+ */
+ private List<String> userNameList;
+
/**
* Default constructor
*/
}
}
+ @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:
@Override
public Date getBirthday () {
- return birthday;
+ return this.birthday;
}
@Override
*/
public User createUserInstance ();
+ /**
+ * Checks whether given user name is used
+ * <p>
+ * @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
+ * <p>
+ * @param emailAddress Email address to check
+ * @return Whether it is already used
+ */
+ public boolean isEmailAddressRegistered (final String emailAddress);
+
/**
* Getter for birth day
* <p>