From e957543331f8fb9455a58f6bda1d190025df04de Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 18 May 2016 09:50:46 +0200 Subject: [PATCH] Continued a bit: - added sending out registration email - added internal TODO --- .../PizzaUserRegistrationSessionBean.java | 28 ++++++++++++++++++- .../PizzaResendLinkSessionBean.java | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/java/org/mxchange/jusercore/model/register/PizzaUserRegistrationSessionBean.java b/src/java/org/mxchange/jusercore/model/register/PizzaUserRegistrationSessionBean.java index 78c37ef..eb40ed7 100644 --- a/src/java/org/mxchange/jusercore/model/register/PizzaUserRegistrationSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/register/PizzaUserRegistrationSessionBean.java @@ -18,7 +18,11 @@ package org.mxchange.jusercore.model.register; import java.text.MessageFormat; 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.Query; import org.mxchange.jcontacts.contact.Contact; @@ -140,6 +144,15 @@ public class PizzaUserRegistrationSessionBean extends BasePizzaDatabaseBean impl if (null == user) { // Abort here throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserContact() == null) { + // Throw NPE again + throw new NullPointerException("user.userContact is null"); //NOI18N + } else if (user.getUserContact().getContactEmailAddress() == null) { + // Throw NPE again + throw new NullPointerException("user.userContact.contactEmailAddress is null"); //NOI18N + } else if (user.getUserContact().getContactEmailAddress().isEmpty()) { + // Is empty + throw new IllegalArgumentException("user.userContact.contactEmailAddress is empty"); //NOI18N } // Check if user is registered @@ -154,7 +167,20 @@ public class PizzaUserRegistrationSessionBean extends BasePizzaDatabaseBean impl // Call other EJB User addedUser = this.userBean.addUser(user); - // Create email + // Init variable + Address emailAddress; + + try { + // Create email address and set + emailAddress = new InternetAddress(user.getUserContact().getContactEmailAddress()); + } catch (final AddressException ex) { + // Throw again + throw new EJBException(ex); + } + + // Send email + // TODO: Internationlize the subject line somehow + this.sendEmail("Registration", "registration", emailAddress, user); //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: addedUser={0},addedUser.userId={1} - EXIT!", addedUser, addedUser.getUserId())); //NOI18N diff --git a/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkSessionBean.java index d1fbc0c..2b95826 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkSessionBean.java @@ -81,6 +81,7 @@ public class PizzaResendLinkSessionBean extends BasePizzaDatabaseBean implements } // Send email + // TODO: Internationlize the subject line somehow this.sendEmail("Resend confirmation link", "resend_confirmation_link", emailAddress, user); //NOI18N // Log trace message -- 2.39.5