import java.text.MessageFormat;
import java.util.GregorianCalendar;
import java.util.List;
-import java.util.Locale;
-import java.util.Properties;
-import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.Stateless;
-import javax.faces.FacesException;
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Queue;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.Session;
import javax.mail.Address;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
import javax.persistence.NoResultException;
import javax.persistence.Query;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
-import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper;
-import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
import org.mxchange.jusercore.model.user.UserUtils;
+import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
/**
* A session bean for changing email addresses
* @author Roland Haeder<roland@mxchange.org>
*/
@Stateless (name = "emailchange", description = "A bean handling email changes")
-public class PizzaEmailChangeSessionBean extends BaseDatabaseBean implements EmailChangeSessionBeanRemote {
+public class PizzaEmailChangeSessionBean extends BasePizzaDatabaseBean implements EmailChangeSessionBeanRemote {
/**
* Serial number
*/
private static final long serialVersionUID = 182_698_165_971_548L;
- /**
- * Connection
- */
- private Connection connection;
-
- /**
- * Object message
- */
- private ObjectMessage message;
-
- /**
- * Message producer
- */
- private MessageProducer messageProducer;
-
- /**
- * Mailer message queue
- */
- private Queue queue;
-
- /**
- * Session instance
- */
- private Session session;
-
/**
* User bean
*/
// Persist it
//this.getEntityManager().persist(emailChange);
- // Prepare mail wrapper
- WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
+ // Init variable
+ Address emailAddress;
try {
// Create email address and set
- Address emailAddress = new InternetAddress(emailChange.getEmailAddress());
- emailWrapper.setRecipient(emailAddress);
+ emailAddress = new InternetAddress(emailChange.getEmailAddress());
} catch (final AddressException ex) {
// Throw again
throw new EJBException(ex);
}
- // Set all values
- Properties variables = UserUtils.getAllUserFields(emailChange.getEmailChangeUser());
-
- // Set all
- // @TODO Get locale from user + language from message bundle
- emailWrapper.setLocale(Locale.GERMAN);
- emailWrapper.setSubjectLine("Email change");
- emailWrapper.setTemplateName("email_change"); //NOI18N
- emailWrapper.setTemplateVariables(variables);
-
- try {
- // Send out email change
- this.message.setObject(emailWrapper);
-
- // Send message
- this.sendMessage(this.message);
- } catch (final JMSException ex) {
- // Throw again
- throw new EJBException(ex);
- }
+ // Send email
+ this.sendEmail("Email change", "email_change", emailAddress, emailChange.getEmailChangeUser()); //NOI18N
// Trace message
this.getLoggerBeanLocal().logTrace("enqueueEmailAddressForChange - EXIT!"); //NOI18N
}
- /**
- * Initialization of this bean
- */
- @PostConstruct
- public void init () {
- // Trace message
- this.getLoggerBeanLocal().logTrace("init: CALLED!"); //NOI18N
-
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Get factory from JMS resource
- QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/jlandingpage-queue-factory"); //NOI18N
-
- // Lookup queue
- this.queue = (Queue) context.lookup("jms/jlandingpage-email-queue"); //NOI18N
-
- // Create connection
- this.connection = connectionFactory.createConnection();
-
- // Init session instance
- this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- // And message producer
- this.messageProducer = this.session.createProducer(this.queue);
-
- // Finally the message instance itself
- this.message = this.session.createObjectMessage();
- } catch (final NamingException | JMSException e) {
- // Continued to throw
- throw new FacesException(e);
- }
- }
-
@Override
public boolean isEmailAddressEnqueued (final String emailAddress) {
// Trace message
emailAddress.setEmailChangeHash(hash);
}
- /**
- * Sends given message to configured queue
- * <p>
- * @param message Message to send
- * <p>
- * @throws JMSException if something went wrong
- */
- private void sendMessage (final ObjectMessage message) throws JMSException {
- // The parameter should be valid
- if (null == message) {
- // Throw NPE
- throw new NullPointerException("message is null"); //NOI18N
- }
-
- // Send it
- this.messageProducer.send(message);
- }
-
}
import de.chotime.landingpage.beans.resendlink.ResendLinkSessionBeanRemote;
import java.text.MessageFormat;
import java.util.Locale;
-import javax.annotation.PostConstruct;
+import javax.ejb.EJBException;
import javax.ejb.Stateless;
-import javax.faces.FacesException;
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Queue;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
+import javax.mail.Address;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
*/
private static final long serialVersionUID = 71_546_726_857_195_360L;
- /**
- * Connection
- */
- private Connection connection;
-
- /**
- * Object message
- */
- private ObjectMessage message;
-
- /**
- * Message producer
- */
- private MessageProducer messageProducer;
-
- /**
- * Mailer message queue
- */
- private Queue queue;
-
- /**
- * Session instance
- */
- private Session session;
-
- /**
- * Initialization of this bean
- */
- @PostConstruct
- public void init () {
- // Trace message
- this.getLoggerBeanLocal().logTrace("init: CALLED!"); //NOI18N
-
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Get factory from JMS resource
- QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/jlandingpage-queue-factory"); //NOI18N
-
- // Lookup queue
- this.queue = (Queue) context.lookup("jms/jlandingpage-email-queue"); //NOI18N
-
- // Create connection
- this.connection = connectionFactory.createConnection();
-
- // Init session instance
- this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- // And message producer
- this.messageProducer = this.session.createProducer(this.queue);
-
- // Finally the message instance itself
- this.message = this.session.createObjectMessage();
- } catch (final NamingException | JMSException e) {
- // Continued to throw
- throw new FacesException(e);
- }
- }
-
@Override
public String resendConfirmationLink (final User user, final Locale locale) {
// Log trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("resendConfirmationLink: user={0} - CALLED!", user)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("resendConfirmationLink: user={0},locale={1} - CALLED!", user, locale)); //NOI18N
// The user instance should be valid
if (null == user) {
throw new NullPointerException("locale is null"); //NOI18N
}
- // @TODO Unfinished!
+ // @TODO Unfinished: Change key + merge database
+
+ // 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
+ this.sendEmail("Resend confirmation link", "resend_confirmation_link", emailAddress, user); //NOI18N
+
+ // Log trace message
+ this.getLoggerBeanLocal().logTrace("resendConfirmationLink: CALLED!"); //NOI18N
+
// All fine
return "resend_done"; //NOI18N
}