From 25064c49521fd517f0dbd889e9afb9f93cb64bf8 Mon Sep 17 00:00:00 2001 From: Michael Wechner Date: Mon, 30 Jan 2012 16:44:45 +0100 Subject: [PATCH] check whether emails should be sent --- src/resources/registration/resource.xml | 1 + .../UserRegistrationResource.java | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/resources/registration/resource.xml b/src/resources/registration/resource.xml index 998db77ff..013462554 100644 --- a/src/resources/registration/resource.xml +++ b/src/resources/registration/resource.xml @@ -17,5 +17,6 @@ User registration + diff --git a/src/resources/registration/src/java/org/wyona/yanel/resources/registration/UserRegistrationResource.java b/src/resources/registration/src/java/org/wyona/yanel/resources/registration/UserRegistrationResource.java index 4ed5f2b88..b21ce0034 100644 --- a/src/resources/registration/src/java/org/wyona/yanel/resources/registration/UserRegistrationResource.java +++ b/src/resources/registration/src/java/org/wyona/yanel/resources/registration/UserRegistrationResource.java @@ -229,8 +229,13 @@ private void sendConfirmationLinkEmail(Document doc, String uuid, String firstam Element rootElement = doc.getDocumentElement(); try { - MailUtil.send(getResourceConfigProperty(FROM_ADDRESS_PROP_NAME), email, "Activate User Registration", getActivationURL(uuid)); - Element element = (Element) rootElement.appendChild(doc.createElementNS(NAMESPACE, "confirmation-link-email-sent")); + Element element = (Element) rootElement.appendChild(doc.createElementNS(NAMESPACE, "confirmation-link-email")); + if (sendNotificationsEnabled()) { + MailUtil.send(getResourceConfigProperty(FROM_ADDRESS_PROP_NAME), email, "Activate User Registration", getActivationURL(uuid)); + element.setAttribute("sent", "true"); + } else { + element.setAttribute("sent", "false"); + } element.setAttribute("hours-valid", "" + DEFAULT_TOTAL_VALID_HRS); if (getResourceConfigProperty("include-activation-link") != null && getResourceConfigProperty("include-activation-link").equals("true")) { log.warn("Activation link will be part of response! Because of security reasons this should only be done for development or testing environments."); @@ -588,7 +593,9 @@ private boolean activateRegistration(String uuid, Document doc) { String homepageURL = getActivationURL(null).replace("registration", "index"); // TODO: Misuse getActivationURL ... homepageURL = homepageURL.substring(0, homepageURL.indexOf("?")); - MailUtil.send(getResourceConfigProperty(FROM_ADDRESS_PROP_NAME), urBean.getEmail(), "User Registration Successful", homepageURL); + if (sendNotificationsEnabled()) { + MailUtil.send(getResourceConfigProperty(FROM_ADDRESS_PROP_NAME), urBean.getEmail(), "User Registration Successful", homepageURL); + } Element rootElement = doc.getDocumentElement(); // TODO: Add gender/salutation @@ -637,6 +644,21 @@ private UserRegistrationBean readRegistrationRequest(Node node) throws Exception return urBean; } + + /** + * Check whether notification emails should be sent (In the case of a "continuous integration" environment one might not want to send emails) + */ + private boolean sendNotificationsEnabled() { + try { + String value = getResourceConfigProperty("send-notification-emails"); + if (value != null && value.equals("false")) { + return false; + } + } catch(Exception e) { + log.error(e, e); + } + return true; + } } /**