From 00c24db09091724bf0e83b7a29ccdfb89c389eaf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 19 May 2016 17:24:38 +0200 Subject: [PATCH] Implemented business method confirmAccount() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../user/AddressbookUserSessionBean.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java index eb0d961..44fd081 100644 --- a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java @@ -22,6 +22,9 @@ import java.util.List; 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; @@ -33,6 +36,8 @@ import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; 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; @@ -171,6 +176,61 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl 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 -- 2.39.5