import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.Stateless;
+import javax.mail.Address;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceException;
import javax.persistence.Query;
import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
+import org.mxchange.jusercore.exceptions.UserStatusLockedException;
import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
return users;
}
+ @Override
+ public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("confirmAccount: user={0},baseUrl={1} - CALLED!", user, baseUrl)); //NOI18N
+
+ // Parameter must be valid
+ if (null == user) {
+ // Abort here
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserId() == null) {
+ // Abort here
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
+ } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
+ // Account is already confirmed
+ throw new UserStatusConfirmedException(user);
+ } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
+ // Account is already confirmed
+ throw new UserStatusLockedException(user);
+ } else if (user.getUserConfirmKey() == null) {
+ // Throw NPE
+ throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
+ }
+
+ // Update user status and remove confirmation key
+ user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
+ user.setUserConfirmKey(null);
+ user.setUserUpdated(new GregorianCalendar());
+
+ // Update user account
+ User updatedUser = this.updateUserData(user);
+
+ // Init variable
+ Address emailAddress;
+
+ try {
+ // Create email address and set
+ emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress());
+ } catch (final AddressException ex) {
+ // Throw again
+ throw new EJBException(ex);
+ }
+
+ // Send out email
+ this.sendEmail("Account confirmed", "account_confirmed", emailAddress, updatedUser, baseUrl); //NOI18N
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("confirmAccount: updatedUser={0} - EXIT!", updatedUser)); //NOI18N
+
+ // Return updated instance
+ return updatedUser;
+ }
+
@Override
public User fillUserData (final User user) {
// Trace message