]> git.mxchange.org Git - addressbook-ejb.git/blobdiff - src/java/org/mxchange/juserlogincore/model/user/register/AddressbookUserRegistrationSessionBean.java
Don't cherry-pick:
[addressbook-ejb.git] / src / java / org / mxchange / juserlogincore / model / user / register / AddressbookUserRegistrationSessionBean.java
index 4d5ad00c5e5cbc09a0347db128a3a70b3ea1a0c1..427a4087f901569258fcafe8bc0600773f8ae638 100644 (file)
 package org.mxchange.juserlogincore.model.user.register;
 
 import java.text.MessageFormat;
+import java.util.List;
 import java.util.Objects;
 import javax.ejb.EJB;
 import javax.ejb.Stateless;
-import javax.persistence.NoResultException;
-import javax.persistence.Query;
 import org.mxchange.addressbook.enterprise.BaseAddressbookEnterpriseBean;
-import org.mxchange.jcontacts.model.contact.Contact;
 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
 import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
 import org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote;
-import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 import org.mxchange.juserlogincore.login.UserLoginUtils;
@@ -76,8 +73,8 @@ public class AddressbookUserRegistrationSessionBean extends BaseAddressbookEnter
                        throw new NullPointerException("user is null"); //NOI18N
                }
 
-               // Create named instance
-               final Query query = this.getEntityManager().createNamedQuery("SearchUserByConfirmKey", LoginUser.class); //NOI18N
+               // Fetch whole list
+               final List<User> users = this.userBean.fetchAllUsers();
 
                // Init confirmation key
                String confirmationKey = null;
@@ -85,22 +82,16 @@ public class AddressbookUserRegistrationSessionBean extends BaseAddressbookEnter
                // Find a free one
                while (confirmationKey == null) {
                        // Create new one
-                       final String key = UserLoginUtils.generatedConfirmationKey(user);
-
-                       // Set key as parameter
-                       query.setParameter("confirmKey", key); //NOI18N
-
-                       // Try it
-                       try {
-                               // Get contact instance
-                               final Contact contact = (Contact) query.getSingleResult();
-
-                               // Warning message
-                               this.getLoggerBeanLocal().logWarning(MessageFormat.format("{0}.generateConfirmationKey: key {1} already found: contact.contactId={2}", this.getClass().getSimpleName(), key, contact.getContactId())); //NOI18N
-                       } catch (final NoResultException ex) {
-                               // Not found, normal case
-                               confirmationKey = key;
-                               break;
+                       confirmationKey = UserLoginUtils.generatedConfirmationKey(user);
+
+                       // Check all entries
+                       for (final User currentUser : users) {
+                               // Does the key match?
+                               if (Objects.equals(currentUser.getUserConfirmKey(), confirmationKey)) {
+                                       // Set key to null and exit loop
+                                       confirmationKey = null;
+                                       break;
+                               }
                        }
                }
 
@@ -154,7 +145,7 @@ public class AddressbookUserRegistrationSessionBean extends BaseAddressbookEnter
 
                // Is password set?
                if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
-                       // Switch to other template
+                       // Switch to template with random password exposed
                        templateName = "user_registration_random"; //NOI18N
                }