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;
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;
// 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;
+ }
}
}
// 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
}