|
From: <ian...@us...> - 2008-02-12 00:15:31
|
Revision: 733
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=733&view=rev
Author: iansmith
Date: 2008-02-11 16:15:34 -0800 (Mon, 11 Feb 2008)
Log Message:
-----------
Added support for the "preferredDomain" and propagated that all the way through the system to make email be "labelled" properly. This option is server.xml and is not required.
Modified Paths:
--------------
maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/VerifyEnvironmentMojo.java
maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/AccountServlet.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/WebappServletBase.java
maven/trunk/ogoglio-server/src/main/webapp/META-INF/context.xml
Modified: maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/VerifyEnvironmentMojo.java
===================================================================
--- maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/VerifyEnvironmentMojo.java 2008-02-10 21:55:34 UTC (rev 732)
+++ maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/VerifyEnvironmentMojo.java 2008-02-12 00:15:34 UTC (rev 733)
@@ -31,7 +31,8 @@
};
private static final String[] OPTIONAL_NAMES= {
- "preferredIPAddr"
+ "preferredIPAddr",
+ "preferredDomain"
};
/**
Modified: maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java
===================================================================
--- maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java 2008-02-10 21:55:34 UTC (rev 732)
+++ maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java 2008-02-12 00:15:34 UTC (rev 733)
@@ -223,6 +223,7 @@
assertFalse(accountDoc.isEmailValid());
String emailValidationURL = getLastEmailValidationURL(accountDoc.getEmail());
assertNotNull(emailValidationURL);
+ Log.debug("CHECKING VALIDATION URL:"+emailValidationURL);
StreamUtils.discardInput(wire1.performGET(URI.create(emailValidationURL), null));
accountDoc = adminWebClient.getAccountDocument(username);
assertTrue(accountDoc.isEmailValid());
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/AccountServlet.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/AccountServlet.java 2008-02-10 21:55:34 UTC (rev 732)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/AccountServlet.java 2008-02-12 00:15:34 UTC (rev 733)
@@ -13,6 +13,7 @@
limitations under the License. */
package com.ogoglio.site;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
@@ -405,20 +406,46 @@
AttachmentRecord[] attachmentRecords = BodyPersistTasks.findAttachmentsByConfigurationID(record.getBodyConfigurationID(), getSessionFactory());
return DocumentFactory.documentFromRecord(record, settingRecords, attachmentRecords);
}
+
+ private String getDomainForExternalUse() {
+ if (preferredDomain!=null) {
+ return preferredDomain;
+ }
+ return getSiteInfo().getHost(); //can be dodgy if you are NOT in the dev case
+ }
+ private String getHostPortionOfURLForExternalUse() {
+ StringBuffer result=new StringBuffer();
+ result.append("http://"+getDomainForExternalUse());
+ //this is a dodgy and evil hack to determine if you want an ugly or pretty URL
+ //if you bothered to make your base URL something that had a port, we repeat it, figuring
+ //that you are on a dev machine and probably need it
+ try {
+ URI uri=new URI(getSiteInfo().getBaseUrl());
+ if ((uri.getPort()!=80) && (uri.getPort()!=-1)) {
+ result.append(":"+uri.getPort());
+ }
+ } catch (URISyntaxException IGNORED) {
+
+ }
+ result.append("/");
+ return result.toString();
+ }
+
private void sendValidationMail(PendingEmailValidationRecord validationRecord) throws MailSendException {
- String from = "robot@" + getSiteInfo().getHost();
- String validationURL = getSiteInfo().getBaseUrl() + "account/validate?" + SECRET_PARAMETER + "=" + validationRecord.getSecret();
+ String from = "dont-reply@" + getDomainForExternalUse();
+ String validationURL = getHostPortionOfURLForExternalUse()+ "og/account/validate?" + SECRET_PARAMETER + "=" + validationRecord.getSecret();
MailFormatter mailFormatter = new MailFormatter();
- Map validationMap = createEmailValidationMap(validationRecord.getEmail(), validationURL, "Ogoglio", getSiteInfo().getBaseUrl());
+ Map validationMap = createEmailValidationMap(validationRecord.getEmail(), validationURL, "Ogoglio", getHostPortionOfURLForExternalUse());
String body = mailFormatter.format(validationMap, getTemplate(EMAIL_VALIDATION_TEMPLATE));
MailClient mailClient = null;
- if (getSiteInfo().getMailDirectory() == null) {
+ File mailDir = getSiteInfo().getMailDirectory() ;
+ if (mailDir == null) {
mailClient = new MailClient();
} else {
- mailClient = new MailClient(getSiteInfo().getMailDirectory());
+ mailClient = new MailClient(mailDir);
}
mailClient.sendEmail(validationRecord.getEmail(), from, "validate request", body);
Log.info("Sent validation email to " + validationRecord.getEmail());
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/WebappServletBase.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/WebappServletBase.java 2008-02-10 21:55:34 UTC (rev 732)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/WebappServletBase.java 2008-02-12 00:15:34 UTC (rev 733)
@@ -10,6 +10,7 @@
protected boolean servletNeeded=true;
protected String preferredIPAddr=null;
+ protected String preferredDomain=null;
public void init(ServletConfig config) throws ServletException {
try {
@@ -21,9 +22,20 @@
}
try {
preferredIPAddr = (String) envCtx.lookup("ogoglio/preferredIPAddr");
+ if ((preferredIPAddr!=null) && (preferredIPAddr.trim().equals(""))) {
+ preferredIPAddr=null;
+ }
} catch (NameNotFoundException e) {
//this is optional
}
+ try {
+ preferredDomain = (String) envCtx.lookup("ogoglio/preferredDomain");
+ if ((preferredDomain!=null) && (preferredDomain.trim().equals(""))) {
+ preferredDomain=null;
+ }
+ } catch (NameNotFoundException e) {
+ //this is optional
+ }
super.init(config);
} catch (NamingException e) {
bailOutOfInit(e);
Modified: maven/trunk/ogoglio-server/src/main/webapp/META-INF/context.xml
===================================================================
--- maven/trunk/ogoglio-server/src/main/webapp/META-INF/context.xml 2008-02-10 21:55:34 UTC (rev 732)
+++ maven/trunk/ogoglio-server/src/main/webapp/META-INF/context.xml 2008-02-12 00:15:34 UTC (rev 733)
@@ -24,5 +24,6 @@
<ResourceLink name="ogoglio/simFilterPort" global="simFilterPort" type="java.lang.String"/>
<ResourceLink name="ogoglio/preferredIPAddr" global="preferredIPAddr" type="java.lang.String"/>
+ <ResourceLink name="ogoglio/preferredDomain" global="preferredDomain" type="java.lang.String"/>
</Context>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|