Skip to content

Commit

Permalink
check whether emails should be sent
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed Jan 30, 2012
1 parent d46a412 commit 25064c4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/resources/registration/resource.xml
Expand Up @@ -17,5 +17,6 @@ User registration
<property name="email-confirmation" default-value="true"/> <!-- INFO: Set to false if no email confirmation/activation should re required. -->
<property name="groups"/> <!-- INFO: Comma separated list of group IDs, to which user shall be added automatically during registration -->
<property name="include-activation-link" default-value="false"/> <!-- WARN: Because of security reasons please do not enable this property for a productive environment, but only set to 'true' for development or a continuous integration environment! -->
<property name="send-notification-emails" default-value="true"/> <!-- INFO: In the case of a continuous integration environment one might want to set this property to 'false' -->
</rtd>
</resource>
Expand Up @@ -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.");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}

/**
Expand Down

0 comments on commit 25064c4

Please sign in to comment.