Author: thomas.heute(a)jboss.com
Date: 2007-03-23 09:58:47 -0400 (Fri, 23 Mar 2007)
New Revision: 6805
Added:
trunk/core/src/resources/portal-core-war/WEB-INF/classes/templates/
trunk/core/src/resources/portal-core-war/WEB-INF/classes/templates/user/
trunk/core/src/resources/portal-core-war/WEB-INF/classes/templates/user/emailTemplate.tpl
trunk/core/src/resources/portal-core-war/WEB-INF/classes/templates/user/emailTemplate_fr.tpl
Modified:
trunk/build/build-thirdparty.xml
trunk/core/.classpath
trunk/core/build.xml
trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource.properties
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource_es.properties
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource_fr.properties
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource_pt_BR.properties
Log:
Email verification using a template
Modified: trunk/build/build-thirdparty.xml
===================================================================
--- trunk/build/build-thirdparty.xml 2007-03-23 10:31:03 UTC (rev 6804)
+++ trunk/build/build-thirdparty.xml 2007-03-23 13:58:47 UTC (rev 6805)
@@ -107,7 +107,8 @@
<componentref name="sun-opends" version="snapshot"/>
<componentref name="sun-servlet" version="2.4"/>
<componentref name="xdoclet" version="1.2.3"/>
- <componentref name="jbpm/jaronly" version="3.1.2"/>
+ <componentref name="jbpm/jaronly" version="3.1.2"/>
+ <componentref name="freemarker" version="2.3.9"/>
<componentref name="wutka-dtdparser" version="1.2.1"/>
</build>
Modified: trunk/core/.classpath
===================================================================
--- trunk/core/.classpath 2007-03-23 10:31:03 UTC (rev 6804)
+++ trunk/core/.classpath 2007-03-23 13:58:47 UTC (rev 6805)
@@ -49,5 +49,6 @@
<classpathentry kind="lib"
path="/thirdparty/jbpm/jaronly/lib/jbpm.jar"/>
<classpathentry combineaccessrules="false" kind="src"
path="/portlet-server"/>
<classpathentry kind="lib"
path="/thirdparty/apache-xerces/lib/xml-apis.jar"/>
+ <classpathentry kind="lib"
path="/thirdparty/freemarker/lib/freemarker.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: trunk/core/build.xml
===================================================================
--- trunk/core/build.xml 2007-03-23 10:31:03 UTC (rev 6804)
+++ trunk/core/build.xml 2007-03-23 13:58:47 UTC (rev 6805)
@@ -91,6 +91,7 @@
<path refid="jboss.cache.classpath"/>
<path refid="jbossas/core.libs.classpath"/>
<path refid="hibernate.hibernate.classpath"/>
+ <path refid="freemarker.freemarker.classpath"/>
<path refid="apache.ant.classpath"/>
<path refid="apache.myfaces.classpath"/>
<path refid="apache.log4j.classpath"/>
@@ -337,6 +338,7 @@
<fileset dir="${javassist.javassist.lib}"
includes="javassist.jar"/>
<fileset dir="${apache.fileupload.lib}"
includes="commons-fileupload.jar"/>
<fileset dir="${jakarta.io.lib}"
includes="commons-io.jar"/>
+ <fileset dir="${freemarker.freemarker.lib}"
includes="freemarker.jar"/>
<fileset dir="${portals.bridges.lib}"
includes="portals-bridges-common.jar"/>
</copy>
Modified: trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java 2007-03-23
10:31:03 UTC (rev 6804)
+++ trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java 2007-03-23
13:58:47 UTC (rev 6805)
@@ -22,16 +22,21 @@
******************************************************************************/
package org.jboss.portal.core.portlet.user;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.PrintWriter;
+import java.io.StringWriter;
import java.net.URL;
+import java.util.Date;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
+import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
-import java.util.Date;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
@@ -59,7 +64,6 @@
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.UserModule;
import org.jboss.portal.identity.UserProfileModule;
-import org.jboss.portal.identity.config.metadata.profile.ProfileMetaData;
import org.jboss.portal.theme.PortalTheme;
import org.jboss.portal.theme.ThemeInfo;
import org.jboss.portal.theme.ThemeService;
@@ -69,6 +73,10 @@
import org.jboss.portlet.JBossRenderRequest;
import org.jboss.portlet.JBossRenderResponse;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
/**
* This portlet aims at managing users
*
@@ -1050,8 +1058,6 @@
// gen link using username, encrypted pw, and a salt.
String hash = Tools.md5AsHexString(user.getUserName() + getProperty(user,
User.INFO_USER_REGISTRATION_DATE).toString() + UserPortletConstants.SALT);
- String rootURL = getPortletConfig().getInitParameter("emailDomain");
-
PortalNode node = req.getPortalNode();
//PortalNodeURL link = resp.createActionURL(node);
@@ -1061,72 +1067,49 @@
link.setParameter(UserPortletConstants.HASH, hash);
link.setRelative(false);
- // TODO: refactor to have a simple text file outside the code that can be
- // easily changed
+ // Fill data to share with the template
+ Map modelRoot = new HashMap();
+ modelRoot.put("emailDomain",
getPortletConfig().getInitParameter("emailDomain"));
+ modelRoot.put("id", user.getId());
+ modelRoot.put("username", user.getUserName());
+ modelRoot.put("password", clearPassword);
+ modelRoot.put("activationLink", link);
- StringBuffer sb = new StringBuffer();
- Locale locale = req.getLocale();
- ResourceBundle bundle = getResourceBundle(locale);
- try
- {
- sb.append(bundle.getString("VALIDATIONEMAIL_1")).append(" -
");
- sb.append(rootURL);
- sb.append("\n\n");
-
sb.append(bundle.getString("VALIDATIONEMAIL_2")).append(":\n\n");
- sb.append("----------------------------\n");
- sb.append(bundle.getString("USERNAME")).append(":
").append(user.getUserName()).append("\n");
- sb.append(bundle.getString("PASSWORD")).append(":
").append(clearPassword).append("\n");
- sb.append("----------------------------\n\n");
- sb.append(bundle.getString("VALIDATIONEMAIL_3")).append(":
\n");
- sb.append(link);
- sb.append("\n\n");
- sb.append(bundle.getString("VALIDATIONEMAIL_4"));
- sb.append("\n\n");
-
sb.append(bundle.getString("VALIDATIONEMAIL_5")).append("\n");
- }
- catch (Exception e)
- {
- log.error("Cannot generate an email notification", e);
- }
-
- return sb.toString();
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param req DOCUMENT_ME
- * @param resp DOCUMENT_ME
- */
- /*
- public void activate(JBossActionRequest req,
- JBossActionResponse resp)
- {
- String hash = req.getParameter(UserPortletConstants.HASH);
- String userId = req.getParameters().getParameter(UserPortletConstants.USERID);
-
- User user;
- try
- {
- user = userModule.findUserById(userId);
- String hexCompare = Tools.md5AsHexString(user.getUserName() + getProperty(user,
User.INFO_USER_REGISTRATION_DATE).toString() + UserPortletConstants.SALT);
- if (hash.equals(hexCompare))
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ String message = null;
+ try {
+ Locale locale = req.getLocale();
+ URL config = tcl.getResource("templates/user/emailTemplate_" +
locale.getLanguage() + "_" + locale.getCountry()+ ".tpl");
+ if (config == null)
{
- //user.setEnabled(true);
- setProperty(user, User.INFO_USER_ENABLED, Boolean.valueOf(true));
- portletHelper.setI18nRenderParameter(req, resp,
UserPortletConstants.INFOMESSAGE, "INFOMESSAGE_CONGRATULATIONACTIVATED");
+ config = tcl.getResource("templates/user/emailTemplate_" +
locale.getLanguage() + ".tpl");
}
- else
+ if (config == null)
{
- portletHelper.setI18nRenderParameter(req, resp,
UserPortletConstants.ERRORMESSAGE, "ERRORMESSAGE_UNABLEACTIVATE");
+ config = tcl.getResource("templates/user/emailTemplate.tpl");
}
+ if (config == null)
+ {
+ throw new FileNotFoundException("Cannot load a suitable
emailTemplate.tpl in templates/user");
+ }
+ InputStream in = config.openStream();
+ Template tpl = new Template("emailTemplate", new
InputStreamReader(in), new Configuration());
+ StringWriter out = new StringWriter();
+ tpl.process(modelRoot, out);
+ out.close();
+ message = out.toString();
}
- catch (Exception e)
+ catch (IOException e1)
{
- portletHelper.setI18nRenderParameter(req, resp,
UserPortletConstants.ERRORMESSAGE, "ERRORMESSAGE_UNABLEACTIVATE");
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (TemplateException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
+
+ return message;
}
- */
private String getFirstName(ResourceBundle bundle, User user)
{
Modified: trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource.properties
===================================================================
---
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource.properties 2007-03-23
10:31:03 UTC (rev 6804)
+++
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource.properties 2007-03-23
13:58:47 UTC (rev 6805)
@@ -305,12 +305,6 @@
ROLE_TEXT_1=Use this portlet to create, edit, delete and add users to roles.
ROLE_TEXT_2=These roles are used in the Management Portlet to set access rights.
-VALIDATIONEMAIL_1=A user with this email address has registered on our site.
-VALIDATIONEMAIL_2=Please keep this email for your records. Your account information is as
follows
-VALIDATIONEMAIL_3=Your account is currently inactive. You cannot use it until you visit
the following link
-VALIDATIONEMAIL_4=If you did not register for membership on our site, no further action
is required.
-VALIDATIONEMAIL_5=Regards,\nThe staff.
-
PERMISSION_PICKPORTLET=Portlet Permissions Administration
PERMISSION_PERMISSIONS=Permissions to modify
PERMISSION_TOP=Select a Component to Modify
Modified: trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource_es.properties
===================================================================
---
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource_es.properties 2007-03-23
10:31:03 UTC (rev 6804)
+++
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource_es.properties 2007-03-23
13:58:47 UTC (rev 6805)
@@ -286,12 +286,6 @@
MENU_EDITROLE=Editar un rol existente
MENU_EDITROLEMEMBERS=Editar los miembros de un rol
-VALIDATIONEMAIL_1=Un usuario con esta direcci�n de email se ha registado en nuestro
sitio.
-VALIDATIONEMAIL_2=Por favor, mantenga este correo para su registro. La informaci�n de su
cuenta es la siguiente
-VALIDATIONEMAIL_3=Su cuenta est� actualmente inactiva. No puede usarla hasta que visite
el siguiente enlace
-VALIDATIONEMAIL_4=Si no se ha registrado como miembro en nuestro sitio, no es necesario
que haga nada m�s.
-VALIDATIONEMAIL_5=Saludos,\nEl personal.
-
PERMISSION_PICKPORTLET=Permisos de administraci�n de portlets
PERMISSION_PERMISSIONS=Permisos para modificaci�n
PERMISSION_TOP=Elegir un componente para modificar
Modified: trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource_fr.properties
===================================================================
---
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource_fr.properties 2007-03-23
10:31:03 UTC (rev 6804)
+++
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource_fr.properties 2007-03-23
13:58:47 UTC (rev 6805)
@@ -254,11 +254,6 @@
MENU_CREATEROLE=Creer nouveau role
MENU_EDITROLE=Editer un role existant
-VALIDATIONEMAIL_1=Un utilisateur s'est enregistre avec cette adresse email.
-VALIDATIONEMAIL_2=Merci de garder cet email. Vos informations sont les suivantes
-VALIDATIONEMAIL_3=Votre compte est desactive pour le moment. Vous en pouvez pas
l'utiliser tant que vous n'aurez pas clique sur le lien suivant
-VALIDATIONEMAIL_4=Si vous n'avez pas demande a etre membre, ne faite rien.
-VALIDATIONEMAIL_5=Cordialement.
TITLE_FILEBROWSE=Explorateur de fichier
_ASREGISTERED=Vous n'avez pas de compte? vous pouvez en cr\u00E9er <a
href\="">un</a>.
Question=Question secr\u00E8te
Modified:
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource_pt_BR.properties
===================================================================
---
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource_pt_BR.properties 2007-03-23
10:31:03 UTC (rev 6804)
+++
trunk/core/src/resources/portal-core-war/WEB-INF/classes/Resource_pt_BR.properties 2007-03-23
13:58:47 UTC (rev 6805)
@@ -284,12 +284,6 @@
MENU_EDITROLE=Editar grupo
MENU_EDITROLEMEMBERS=Editar membros do grupo
-VALIDATIONEMAIL_1=Um usu�rio com este endere�o de email j� existe em nosso sistema.
-VALIDATIONEMAIL_2=Mantenha esse email salvo. As informa��es de sua conta est�o a seguir
-VALIDATIONEMAIL_3=Sua conta esta atualmente inativa. Voc� n�o pode utiliz�-la at� visitar
o link
-VALIDATIONEMAIL_4=Se voc� n�o se cadastrar em nosso site, nenhuma outra a��o �
necess�ria.
-VALIDATIONEMAIL_5=Atenciosamente,\nA Ger�ncia.
-
PERMISSION_PICKPORTLET=Administra��o de Permiss�es de Portlet
PERMISSION_PERMISSIONS=Permiss�es para modificar
PERMISSION_TOP=Selecione um Componente para Modificar
Added:
trunk/core/src/resources/portal-core-war/WEB-INF/classes/templates/user/emailTemplate.tpl
===================================================================
---
trunk/core/src/resources/portal-core-war/WEB-INF/classes/templates/user/emailTemplate.tpl
(rev 0)
+++
trunk/core/src/resources/portal-core-war/WEB-INF/classes/templates/user/emailTemplate.tpl 2007-03-23
13:58:47 UTC (rev 6805)
@@ -0,0 +1,15 @@
+Hello,
+
+you tried to create an account on ${emailDomain}
+
+The user information are written here for your convenience:
+Username: ${username}
+Password: ${password}
+
+At this time, your account is not activated and you will need to access the following URL
to be able to login.
+${activationLink}
+
+If you didn't ask to create an account, we apologize and no further action is
required.
+
+Best regards,
+${emailDomain}
Added:
trunk/core/src/resources/portal-core-war/WEB-INF/classes/templates/user/emailTemplate_fr.tpl
===================================================================
---
trunk/core/src/resources/portal-core-war/WEB-INF/classes/templates/user/emailTemplate_fr.tpl
(rev 0)
+++
trunk/core/src/resources/portal-core-war/WEB-INF/classes/templates/user/emailTemplate_fr.tpl 2007-03-23
13:58:47 UTC (rev 6805)
@@ -0,0 +1,15 @@
+Bonjour
+
+vous avez créé un compte sur ${emailDomain}
+
+Voici les informations de connexion relatives a ce compte:
+Identifiant: ${username}
+Mot de passe: ${password}
+
+Votre compte n'est pas actif pour le moment et vous devez vous rendre à l'adresse
suivante pour l'activer.
+${activationLink}
+
+Si vous n'avez pas créé de compte, nous vous prions de bien vouloir nous excuser et
vous pouvez simplement ignorer cet email.
+
+Cordialement,
+${emailDomain}