detachedContact.setContactEntryUpdated(new Date());
// Get contact from it and find it
- final Contact foundContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId());
-
- // Should be found
- assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N
+ final Contact foundContact = this.createManaged(detachedContact);
// Debug message
this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeContactData: foundContact.contactId={0}", foundContact.getContactId())); //NOI18N
detachedDepartment.setDepartmentEntryUpdated(new Date());
// Get contact from it and find it
- final Department foundDepartment = this.getEntityManager().find(detachedDepartment.getClass(), detachedDepartment.getDepartmentId());
-
- // Should be found
- assert (foundDepartment instanceof Department) : MessageFormat.format("Department with id {0} not found, but should be.", detachedDepartment.getDepartmentId()); //NOI18N
+ final Department foundDepartment = this.createManaged(detachedDepartment);
// Debug message
this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeDepartmentData: foundContact.contactId={0}", foundDepartment.getDepartmentId())); //NOI18N
}
// Set created timestamp
- user.setUserCreated(new Date());
+ user.setUserEntryCreated(new Date());
user.getUserContact().setContactEntryCreated(new Date());
// Update mobile, land-line and fax instance
user.setUserContact(foundContact);
// Set timestamp
- user.setUserCreated(new Date());
+ user.setUserEntryCreated(new Date());
// Perist it
this.getEntityManager().persist(user);
}
@Override
- public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException {
+ public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException, UserNotFoundException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
// Update user status and remove confirmation key
managedUser.setUserAccountStatus(UserAccountStatus.CONFIRMED);
managedUser.setUserConfirmKey(null);
- managedUser.setUserUpdated(new Date());
+ managedUser.setUserEntryUpdated(new Date());
// Send out email
this.sendEmail("User account confirmed", "user_account_confirmed", managedUser, baseUrl, null); //NOI18N
}
@Override
- public User updateUserData (final User detachedUser) {
+ public User updateUserData (final User detachedUser) throws UserNotFoundException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: detachedUser={1} - CALLED!", this.getClass().getSimpleName(), detachedUser)); //NOI18N
throw new NullPointerException("detachedUser.userAccountStatus is null"); //NOI18N
} else if (!this.ifUserExists(detachedUser)) {
// User does not exist
- throw new EJBException(MessageFormat.format("User with id {0} does not exist.", detachedUser.getUserId())); //NOI18N
+ throw new UserNotFoundException(detachedUser.getUserId());
}
// Remove contact instance as this is not updated
assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not merged, but should be.", managedUser.getUserId()); //NOI18N
// Set as updated
- managedUser.setUserUpdated(new Date());
+ managedUser.setUserEntryUpdated(new Date());
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: managedUser={1} - CALLED!", this.getClass().getSimpleName(), managedUser)); //NOI18N
final User managedUser = this.updateUserData(user);
// Update user account
- managedUser.setUserUpdated(new Date());
+ managedUser.setUserEntryUpdated(new Date());
// Create history entry
PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), managedUser);
Users.copyUserData(user, managedUser);
// Set as updated
- managedUser.setUserUpdated(new Date());
+ managedUser.setUserEntryUpdated(new Date());
// Update user data
final Contact managedContact = this.mergeContactData(managedUser.getUserContact());
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.jcontacts.model.contact.Contact;
import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean;
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
}