Author: jkoster
Date: 2009-06-05 11:50:26 +0200 (Fri, 05 Jun 2009)
New Revision: 35755

Modified:
   
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/AbstractLoginPortlet.java
   
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/LoginPortlet.java
   
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/RegisterPortlet.java
   
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/UnregisterPortlet.java
Log:
CMSC-1421 - Confirmation files in EditDefaults are not read correctly: wrong 
path used

Modified: 
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/AbstractLoginPortlet.java
===================================================================
--- 
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/AbstractLoginPortlet.java
       2009-06-05 09:50:24 UTC (rev 35754)
+++ 
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/AbstractLoginPortlet.java
       2009-06-05 09:50:26 UTC (rev 35755)
@@ -1,216 +1,218 @@
-package com.finalist.cmsc.portlets;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.PortletException;
-import javax.portlet.PortletPreferences;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import net.sf.mmapps.modules.cloudprovider.CloudProviderFactory;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.mmbase.bridge.Cloud;
-import org.mmbase.bridge.Node;
-import org.mmbase.bridge.NodeList;
-import org.mmbase.bridge.Relation;
-import org.mmbase.bridge.util.SearchUtil;
-
-import com.finalist.cmsc.mmbase.PropertiesUtil;
-import com.finalist.cmsc.mmbase.RelationUtil;
-import com.finalist.cmsc.navigation.NavigationUtil;
-import com.finalist.cmsc.portalImpl.PortalConstants;
-import com.finalist.cmsc.services.community.person.Person;
-import com.finalist.cmsc.services.community.security.Authentication;
-import com.finalist.cmsc.services.publish.Publish;
-import com.finalist.cmsc.services.sitemanagement.SiteManagement;
-import com.finalist.cmsc.util.HttpUtil;
-
-public abstract class AbstractLoginPortlet extends CmscPortlet{
-   
-   protected String DEFAULT_EMAIL_CONFIRM_TEMPLATE = 
"../templates/view/login/confirmation.txt";
-   protected static final String EMAIL_SUBJECT = "emailSubject";
-   protected static final String EMAIL_TEXT = "emailText";
-   protected static final String EMAIL_FROMEMAIL = "emailFromEmail";
-   protected static final String EMAIL_FROMNAME = "emailFromName";
-   protected static final String REGISTRATIONPAGE = "registrationpage";
-   protected static final String REGISTRATIONPAGEPATH = "registrationpagepath";
-   protected static final String PAGE = "page";
-   public static final String DEFAULT_EMAILREGEX = 
"^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$";
-
-   
-   private static final Log log = 
LogFactory.getLog(AbstractLoginPortlet.class);
-   
-   protected void doEditDefaults(RenderRequest req, RenderResponse res) throws 
IOException,
-   PortletException {
-      PortletPreferences preferences = req.getPreferences();
-      setAttribute(req, EMAIL_SUBJECT, preferences.getValue(EMAIL_SUBJECT,""));
-     // setAttribute(req, EMAIL_TEXT, 
preferences.getValue(EMAIL_TEXT,getConfirmationTemplate()));
-      setAttribute(req, EMAIL_TEXT, 
preferences.getValue(EMAIL_TEXT,getConfirmationTemplate()));
-      setAttribute(req, EMAIL_FROMEMAIL, 
preferences.getValue(EMAIL_FROMEMAIL,""));
-      setAttribute(req, EMAIL_FROMNAME, 
preferences.getValue(EMAIL_FROMNAME,""));
-      String pageid = preferences.getValue(PAGE, null);
-      if (StringUtils.isNotEmpty(pageid)) {
-         String pagepath = SiteManagement.getPath(Integer.valueOf(pageid), 
true);
-         if (pagepath != null) {
-            setAttribute(req, "pagepath", pagepath);
-         }
-      }
-      super.doEditDefaults(req, res);
-   }
-   
-   @Override
-   public void processEditDefaults(ActionRequest request,
-         ActionResponse response) throws PortletException, IOException {
-      PortletPreferences preferences = request.getPreferences();
-      String portletId = 
preferences.getValue(PortalConstants.CMSC_OM_PORTLET_ID, null);
-      if (portletId != null) {
-         // get the values submitted with the form
-         setPortletNodeParameter(portletId, PAGE, request.getParameter(PAGE));
-         String registrationpage = request.getParameter(REGISTRATIONPAGE);
-         setPortletNodeParameter(portletId, REGISTRATIONPAGE, 
registrationpage);
-         if(StringUtils.isNotEmpty(registrationpage)){
-            Cloud cloud = CloudProviderFactory.getCloudProvider().getCloud();
-            String registrationpagepath = 
NavigationUtil.getNavigationItemUrl((HttpServletRequest)request, 
(HttpServletResponse)response, 
cloud.getNode(Integer.valueOf(registrationpage)));
-            if(registrationpagepath != null){
-               setPortletParameter(portletId, REGISTRATIONPAGEPATH, 
registrationpagepath);
-            }
-         } else {
-            setPortletParameter(portletId, REGISTRATIONPAGEPATH, "");
-         }
-         setPortletParameter(portletId, EMAIL_SUBJECT, 
request.getParameter(EMAIL_SUBJECT));
-         setPortletParameter(portletId, EMAIL_TEXT, 
request.getParameter(EMAIL_TEXT));
-         setPortletParameter(portletId, EMAIL_FROMEMAIL, 
request.getParameter(EMAIL_FROMEMAIL));
-         setPortletParameter(portletId, EMAIL_FROMNAME, 
request.getParameter(EMAIL_FROMNAME));
-      }
-      super.processEditDefaults(request, response);
-   }
-   
-   protected String getEmailBody(String emailText,ActionRequest request, 
-         Authentication authentication, Person person) {
-
-      Cloud cloud = getCloudForAnonymousUpdate(false);
-      String pageId = request.getParameter("page");
-
-      if (cloud.hasNode(pageId)) {
-         String url = getConfirmationLink(cloud, Integer.parseInt(pageId));
-         String confirmUrl = HttpUtil.getWebappUri((HttpServletRequest) 
request)
-               + "login/confirm.do?s=" + authentication.getId() + url;
-         
-         return formatConfirmationText(emailText, authentication, person, 
confirmUrl);
-      }
-      return null;
-   }
-
-   protected String formatConfirmationText(String emailText, Authentication 
authentication, Person person, String confirmUrl) {
-      return String.format(emailText == 
null?getConfirmationTemplate():emailText, authentication
-            .getUserId(), authentication.getPassword(), person.getFirstName(),
-            person.getInfix(), person.getLastName(), confirmUrl);
-   }
-
-   protected Cloud getCloudForAnonymousUpdate(boolean isRemote) {
-      Cloud cloud = CloudProviderFactory.getCloudProvider().getCloud();
-      if (isRemote) {
-         return Publish.getRemoteCloud(cloud);
-      }
-      return cloud;
-   }
-
-   protected String getConfirmationLink(Cloud cloud, int pageNode) {
-      String link = null;
-      NodeList portletDefinations = SearchUtil.findNodeList(cloud,
-            "portletdefinition", "definition", this.getPortletName());
-      Node regiesterPortletDefination = portletDefinations.getNode(0);
-      if (portletDefinations.size() > 1) {
-         log.error("found " + portletDefinations.size()
-               + " regiesterPortlet nodes; first one will be used");
-      }
-      NodeList portlets = regiesterPortletDefination.getRelatedNodes("portlet",
-            "definitionrel", SearchUtil.SOURCE);
-      Node portlet = null;
-      Relation relation = null;
-      Node page = cloud.getNode(pageNode);
-      
-      if (page == null) {
-         return null;
-      }
-      
-      NodeList nodeList = page.getRelatedNodes("portlet", "portletrel", 
SearchUtil.DESTINATION);
-      for (int i =0 ; i < nodeList.size() ; i++) {
-         for (int j = 0 ; j < portlets.size() ; j++) {
-            if (nodeList.getNode(i).getNumber() == 
portlets.getNode(j).getNumber()) {
-               portlet = nodeList.getNode(i);
-            }
-         }
-      }
-      
-      relation = 
RelationUtil.getRelation(cloud.getRelationManager("portletrel"), 
page.getNumber(), portlet.getNumber());
-      link = "&pn=" + page.getNumber();  
-      if (relation != null) {
-         String name = relation.getStringValue("name");
-         if (name != null) {
-            link += "&nm=" + name;
-         }
-      }
-      
-      return link;
-   }
-   
-   protected String getConfirmationTemplate() {
-      InputStream is = Thread.currentThread().getContextClassLoader()
-            .getResourceAsStream(getEmailConfirmTemplate());
-
-      if (is == null) {
-         throw new NullPointerException(
-               "The confirmation template file confirmation.txt in directory 
'templates/view/login' does't exist.");
-      }
-      
-      BufferedReader reader = new BufferedReader(new InputStreamReader(is));
-      StringBuilder sb = new StringBuilder();
-      
-      try {
-         String strLine;
-         while ((strLine = reader.readLine()) != null) {
-            sb.append(strLine + "\n");
-         }
-         is.close();
-      } catch (IOException e) {
-         log.error("error happened when reading email template", e);
-      }
-
-      return sb.toString();
-   }
-   
-   protected String getEmailConfirmTemplate() {
-      return DEFAULT_EMAIL_CONFIRM_TEMPLATE;
-   }
-   
-   protected boolean isEmailAddress(String emailAddress) {
-      if (emailAddress == null) {
-         return false;
-      }
-      if (StringUtils.isBlank(emailAddress)) {
-         return false;
-      }
-
-      String emailRegex = getEmailRegex();
-      return emailAddress.trim().matches(emailRegex);
-   }
-
-   protected String getEmailRegex() {
-      String emailRegex = PropertiesUtil.getProperty("email.regex");
-      if (StringUtils.isNotBlank(emailRegex)) {
-         return emailRegex;
-      }
-      return DEFAULT_EMAILREGEX;
-   }
-}
+package com.finalist.cmsc.portlets;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletPreferences;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import net.sf.mmapps.modules.cloudprovider.CloudProviderFactory;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mmbase.bridge.Cloud;
+import org.mmbase.bridge.Node;
+import org.mmbase.bridge.NodeList;
+import org.mmbase.bridge.Relation;
+import org.mmbase.bridge.util.SearchUtil;
+
+import com.finalist.cmsc.mmbase.PropertiesUtil;
+import com.finalist.cmsc.mmbase.RelationUtil;
+import com.finalist.cmsc.navigation.NavigationUtil;
+import com.finalist.cmsc.portalImpl.PortalConstants;
+import com.finalist.cmsc.services.community.person.Person;
+import com.finalist.cmsc.services.community.security.Authentication;
+import com.finalist.cmsc.services.publish.Publish;
+import com.finalist.cmsc.services.sitemanagement.SiteManagement;
+import com.finalist.cmsc.util.HttpUtil;
+
+public abstract class AbstractLoginPortlet extends CmscPortlet{
+   
+   protected String DEFAULT_EMAIL_CONFIRM_TEMPLATE = 
"/WEB-INF/templates/view/login/confirmation.txt";
+   protected static final String EMAIL_SUBJECT = "emailSubject";
+   protected static final String EMAIL_TEXT = "emailText";
+   protected static final String EMAIL_FROMEMAIL = "emailFromEmail";
+   protected static final String EMAIL_FROMNAME = "emailFromName";
+   protected static final String REGISTRATIONPAGE = "registrationpage";
+   protected static final String REGISTRATIONPAGEPATH = "registrationpagepath";
+   protected static final String PAGE = "page";
+   public static final String DEFAULT_EMAILREGEX = 
"^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$";
+
+   private static final Log log = 
LogFactory.getLog(AbstractLoginPortlet.class);
+
+   
+   protected void doEditDefaults(RenderRequest req, RenderResponse res) throws 
IOException,
+   PortletException {
+      PortletPreferences preferences = req.getPreferences();
+      setAttribute(req, EMAIL_SUBJECT, preferences.getValue(EMAIL_SUBJECT,""));
+     // setAttribute(req, EMAIL_TEXT, 
preferences.getValue(EMAIL_TEXT,getConfirmationTemplate()));
+      setAttribute(req, EMAIL_TEXT, 
preferences.getValue(EMAIL_TEXT,getConfirmationTemplate()));
+      setAttribute(req, EMAIL_FROMEMAIL, 
preferences.getValue(EMAIL_FROMEMAIL,""));
+      setAttribute(req, EMAIL_FROMNAME, 
preferences.getValue(EMAIL_FROMNAME,""));
+      String pageid = preferences.getValue(PAGE, null);
+      if (StringUtils.isNotEmpty(pageid)) {
+         String pagepath = SiteManagement.getPath(Integer.valueOf(pageid), 
true);
+         if (pagepath != null) {
+            setAttribute(req, "pagepath", pagepath);
+         }
+      }
+      super.doEditDefaults(req, res);
+   }
+   
+   @Override
+   public void processEditDefaults(ActionRequest request,
+         ActionResponse response) throws PortletException, IOException {
+      PortletPreferences preferences = request.getPreferences();
+      String portletId = 
preferences.getValue(PortalConstants.CMSC_OM_PORTLET_ID, null);
+      if (portletId != null) {
+         // get the values submitted with the form
+         setPortletNodeParameter(portletId, PAGE, request.getParameter(PAGE));
+         String registrationpage = request.getParameter(REGISTRATIONPAGE);
+         setPortletNodeParameter(portletId, REGISTRATIONPAGE, 
registrationpage);
+         if(StringUtils.isNotEmpty(registrationpage)){
+            Cloud cloud = CloudProviderFactory.getCloudProvider().getCloud();
+            String registrationpagepath = 
NavigationUtil.getNavigationItemUrl((HttpServletRequest)request, 
(HttpServletResponse)response, 
cloud.getNode(Integer.valueOf(registrationpage)));
+            if(registrationpagepath != null){
+               setPortletParameter(portletId, REGISTRATIONPAGEPATH, 
registrationpagepath);
+            }
+         } else {
+            setPortletParameter(portletId, REGISTRATIONPAGEPATH, "");
+         }
+         setPortletParameter(portletId, EMAIL_SUBJECT, 
request.getParameter(EMAIL_SUBJECT));
+         setPortletParameter(portletId, EMAIL_TEXT, 
request.getParameter(EMAIL_TEXT));
+         setPortletParameter(portletId, EMAIL_FROMEMAIL, 
request.getParameter(EMAIL_FROMEMAIL));
+         setPortletParameter(portletId, EMAIL_FROMNAME, 
request.getParameter(EMAIL_FROMNAME));
+      }
+      super.processEditDefaults(request, response);
+   }
+   
+   protected String getEmailBody(String emailText,ActionRequest request, 
+         Authentication authentication, Person person) {
+
+      Cloud cloud = getCloudForAnonymousUpdate(false);
+      String pageId = request.getParameter("page");
+
+      if (cloud.hasNode(pageId)) {
+         String url = getConfirmationLink(cloud, Integer.parseInt(pageId));
+         String confirmUrl = HttpUtil.getWebappUri((HttpServletRequest) 
request)
+               + "login/confirm.do?s=" + authentication.getId() + url;
+         
+         return formatConfirmationText(emailText, authentication, person, 
confirmUrl);
+      }
+      return null;
+   }
+
+   protected String formatConfirmationText(String emailText, Authentication 
authentication, Person person, String confirmUrl) {
+      return String.format(emailText == 
null?getConfirmationTemplate():emailText, authentication
+            .getUserId(), authentication.getPassword(), person.getFirstName(),
+            person.getInfix(), person.getLastName(), confirmUrl);
+   }
+
+   protected Cloud getCloudForAnonymousUpdate(boolean isRemote) {
+      Cloud cloud = CloudProviderFactory.getCloudProvider().getCloud();
+      if (isRemote) {
+         return Publish.getRemoteCloud(cloud);
+      }
+      return cloud;
+   }
+
+   protected String getConfirmationLink(Cloud cloud, int pageNode) {
+      String link = null;
+      NodeList portletDefinations = SearchUtil.findNodeList(cloud,
+            "portletdefinition", "definition", this.getPortletName());
+      Node regiesterPortletDefination = portletDefinations.getNode(0);
+      if (portletDefinations.size() > 1) {
+         log.error("found " + portletDefinations.size()
+               + " registerPortlet nodes; first one will be used");
+      }
+      NodeList portlets = regiesterPortletDefination.getRelatedNodes("portlet",
+            "definitionrel", SearchUtil.SOURCE);
+      Node portlet = null;
+      Relation relation = null;
+      Node page = cloud.getNode(pageNode);
+      
+      if (page == null) {
+         return null;
+      }
+      
+      NodeList nodeList = page.getRelatedNodes("portlet", "portletrel", 
SearchUtil.DESTINATION);
+      for (int i =0 ; i < nodeList.size() ; i++) {
+         for (int j = 0 ; j < portlets.size() ; j++) {
+            if (nodeList.getNode(i).getNumber() == 
portlets.getNode(j).getNumber()) {
+               portlet = nodeList.getNode(i);
+            }
+         }
+      }
+      
+      relation = 
RelationUtil.getRelation(cloud.getRelationManager("portletrel"), 
page.getNumber(), portlet.getNumber());
+      link = "&pn=" + page.getNumber();  
+      if (relation != null) {
+         String name = relation.getStringValue("name");
+         if (name != null) {
+            link += "&nm=" + name;
+         }
+      }
+      
+      return link;
+   }
+   
+   protected String getConfirmationTemplate() {
+      InputStream is = 
getPortletContext().getResourceAsStream(getEmailConfirmTemplate());
+
+      if (is == null) {
+         log.warn("The confirmation template file '" + 
getEmailConfirmTemplate() + "' does not exist while loading EditDefaults. Using 
the default empty String for now.");
+         return ""; 
+      }
+      
+      BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+      StringBuilder sb = new StringBuilder();
+      
+      try {
+         String strLine;
+         while ((strLine = reader.readLine()) != null) {
+            sb.append(strLine + "\n");
+         }
+         is.close();
+      } catch (IOException e) {
+         log.error("error happened when reading email template file", e);
+      }
+
+      return sb.toString();
+   }
+   
+   /**
+    * @return path and filename, starting in context root. E.g. 
/WEB-INF/templates/hello.txt
+    */
+   protected String getEmailConfirmTemplate() {
+      return DEFAULT_EMAIL_CONFIRM_TEMPLATE;
+   }
+   
+   protected boolean isEmailAddress(String emailAddress) {
+      if (emailAddress == null) {
+         return false;
+      }
+      if (StringUtils.isBlank(emailAddress)) {
+         return false;
+      }
+
+      String emailRegex = getEmailRegex();
+      return emailAddress.trim().matches(emailRegex);
+   }
+
+   protected String getEmailRegex() {
+      String emailRegex = PropertiesUtil.getProperty("email.regex");
+      if (StringUtils.isNotBlank(emailRegex)) {
+         return emailRegex;
+      }
+      return DEFAULT_EMAILREGEX;
+   }
+}

Modified: 
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/LoginPortlet.java
===================================================================
--- 
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/LoginPortlet.java
       2009-06-05 09:50:24 UTC (rev 35754)
+++ 
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/LoginPortlet.java
       2009-06-05 09:50:26 UTC (rev 35755)
@@ -1,214 +1,213 @@
-/*
-
- This software is OSI Certified Open Source Software.
- OSI Certified is a certification mark of the Open Source Initiative.
-
- The license (Mozilla version 1.0) can be read at the MMBase site.
- See http://www.MMBase.org/license
-
- */
-package com.finalist.cmsc.portlets;
-
-import java.io.IOException;
-
-import javax.mail.MessagingException;
-import javax.mail.internet.AddressException;
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.PortletException;
-import javax.portlet.PortletPreferences;
-import javax.portlet.PortletSession;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import net.sf.mmapps.modules.cloudprovider.CloudProviderFactory;
-import com.finalist.cmsc.login.PasswordGenerator;
-import com.finalist.cmsc.navigation.NavigationUtil;
-import com.finalist.cmsc.services.community.ApplicationContextFactory;
-import com.finalist.cmsc.services.community.Community;
-import com.finalist.cmsc.services.community.person.Person;
-import com.finalist.cmsc.services.community.person.PersonService;
-import com.finalist.cmsc.services.community.person.RegisterStatus;
-import com.finalist.cmsc.services.community.security.Authentication;
-import com.finalist.cmsc.services.community.security.AuthenticationService;
-import com.finalist.cmsc.util.EmailSender;
-import org.mmbase.bridge.Cloud;
-
-/**
- * Login portlet
- *
- * @author Remco Bos
- */
-public class LoginPortlet extends AbstractLoginPortlet {
-   
-   public static final String ERRORMESSAGE = "errormessage";
-
-   protected static final String ACTION_PARAMETER = "action";
-
-   protected static final String ACEGI_SECURITY_FORM_USERNAME_KEY = 
"j_username";
-   protected static final String ACEGI_SECURITY_FORM_PASSWORD_KEY = 
"j_password";
-   protected static final String EMAIL_TEMPLATE_DIR = 
"../templates/view/login/forgotpassword.txt";
-   
-   protected static final String SEND_PASSWORD = "send_password";
-
-   protected static final Log log = LogFactory.getLog(LoginPortlet.class);
-   
-   protected void doEditDefaults(RenderRequest req, RenderResponse res) throws 
IOException,
-   PortletException {
-      super.DEFAULT_EMAIL_CONFIRM_TEMPLATE = EMAIL_TEMPLATE_DIR;
-      super.doEditDefaults(req, res);
-   }
-   
-   @Override
-   public void processView(ActionRequest request, ActionResponse response) 
throws PortletException, IOException {
-      String action = request.getParameter(ACTION_PARAMETER);
-      PortletPreferences preferences = request.getPreferences();
-      
-      if ("login".equals(action)) {
-         String userName = 
request.getParameter(ACEGI_SECURITY_FORM_USERNAME_KEY);
-         String password = 
request.getParameter(ACEGI_SECURITY_FORM_PASSWORD_KEY);
-         String send_password =  request.getParameter(SEND_PASSWORD);
-         
-         if (StringUtils.isEmpty(send_password)) {
-            
-            if (StringUtils.isNotBlank(userName) && 
StringUtils.isNotBlank(password)) {
-               Community.login(userName, password);
-            } else {
-               if (StringUtils.isBlank(userName)) {
-                  response.setRenderParameter(ERRORMESSAGE, 
"register.email.empty");
-               } else {
-                  response.setRenderParameter(ERRORMESSAGE, 
"register.password.empty");
-               }
-
-               return; //Because one of the required fields are empty, there 
is nothing to check anymore
-            }
-            
-            if (Community.isAuthenticated()) {
-               request.getPortletSession().setAttribute("username", userName, 
PortletSession.APPLICATION_SCOPE);
-               String pageid = preferences.getValue(PAGE, null);
-               if (StringUtils.isNotEmpty(pageid)) {
-                  Cloud cloud = 
CloudProviderFactory.getCloudProvider().getCloud();
-                  String redirectUrl = 
NavigationUtil.getNavigationItemUrl((HttpServletRequest)request, 
(HttpServletResponse)response, cloud.getNode(Integer.valueOf(pageid)));
-                  response.sendRedirect(redirectUrl);
-               }
-               log.info(String.format("Login successful for user %s", 
userName));
-            } else {
-               
-               PersonService personHibernateService = (PersonService) 
ApplicationContextFactory.getBean("personService");
-               Person person = 
personHibernateService.getPersonByUserId(userName);
-               
-               if (person != null && 
RegisterStatus.UNCONFIRMED.getName().equalsIgnoreCase(person.getActive())) {
-                  response.setRenderParameter(ERRORMESSAGE, 
"view.account.unconfirmed");
-               }
-               else if (person != null && 
RegisterStatus.BLOCKED.getName().equalsIgnoreCase(person.getActive())) {
-                  response.setRenderParameter(ERRORMESSAGE, 
"view.account.blocked");
-               } else {
-                  log.info(String.format("Login failed for user %s", 
userName));
-                  response.setRenderParameter(ERRORMESSAGE, "login.failed");
-               }
-            }
-         }
-         else {
-            response.setRenderParameter(SEND_PASSWORD, "send");
-         }
-      } else if ("logout".equals(action)) {
-         request.getPortletSession().removeAttribute("username", 
PortletSession.APPLICATION_SCOPE);
-         Community.logout();
-         
-      } else if ("send_password".equals(action)) {
-         //TODO  send password
-         String email =  request.getParameter("username");
-         String sendMessage = "view.account.success";
-         AuthenticationService authenticationService = (AuthenticationService) 
ApplicationContextFactory
-         .getBean("authenticationService");
-         PersonService personHibernateService = (PersonService) 
ApplicationContextFactory.getBean("personService");
-
-         if (authenticationService.authenticationExists(email)) {
-            Person person = personHibernateService.getPersonByUserId(email);
-            Authentication authentication = 
authenticationService.findAuthentication(email);
-           
if(RegisterStatus.ACTIVE.getName().equalsIgnoreCase(person.getActive()) || 
RegisterStatus.UNCONFIRMED.getName().equalsIgnoreCase(person.getActive()))
-           {
-              //todo reset password and send mail 
-              PasswordGenerator generator = new PasswordGenerator();
-              String newPassword = null;
-              try {
-                 newPassword = 
generator.generate(PasswordGenerator.PRINTABLE_CHARACTERS, 7);
-                 authenticationService.updateAuthentication(email, 
authentication.getPassword(), newPassword);
-                 authentication.setPassword(newPassword);
-                 String emailSubject = 
preferences.getValue(EMAIL_SUBJECT,"Your account details associated with the 
given email address.\n");
-                 String emailText = preferences.getValue(EMAIL_TEXT, null);
-                 String emailFrom = preferences.getValue(EMAIL_FROMEMAIL, 
null);
-                 String nameFrom = preferences.getValue(EMAIL_FROMNAME, null);
-                 emailText = getEmailBody(emailText,request, authentication, 
person);
-                 if (StringUtils.isNotBlank(emailFrom) && 
!isEmailAddress(emailFrom)) {
-                    throw new AddressException("Email address "+emailFrom+"is 
not availalbe");
-                 }
-                 EmailSender.sendEmail(emailFrom, nameFrom, email, 
emailSubject, emailText,
-                             email, "text/plain;charset=utf-8");
-                 sendMessage = "view.account.success";
-              } 
-              catch (AddressException e) {
-                 log.error("Email address failed",e);
-              } 
-              catch (MessagingException e) {
-                 log.error("Email MessagingException failed",e);
-              }
-              catch (Exception e) {
-                 log.error(e);
-              } 
-           }
-           else if 
(RegisterStatus.BLOCKED.getName().equalsIgnoreCase(person.getActive())){
-              sendMessage = "view.account.blocked"; 
-           }
-         } 
-         else {
-            //log.info("add authenticationId failed");
-            sendMessage = "view.account.notexist"; 
-         }
-         response.setRenderParameter(SEND_PASSWORD, sendMessage);
-      } 
-      else {
-         // Unknown
-         log.error(String.format("Unknown action '%s'", action));
-      }
-   }
-
-   @Override
-   protected void doView(RenderRequest request, RenderResponse response) 
throws PortletException, IOException {
-      
-      String template;
-      String error = request.getParameter(ERRORMESSAGE);
-      String send_password = request.getParameter(SEND_PASSWORD);
-      PortletPreferences preferences = request.getPreferences();
-      String registrationpagepath = preferences.getValue(REGISTRATIONPAGEPATH, 
null);
-      if(StringUtils.isNotEmpty(registrationpagepath)){
-         request.setAttribute(REGISTRATIONPAGEPATH, registrationpagepath);
-      }
-      if (StringUtils.isNotBlank(error)) {
-         request.setAttribute(ERRORMESSAGE, error);
-      }
-      if (Community.isAuthenticated()) {
-         template = "login/logout.jsp";
-      } else {
-         template = "login/login.jsp";
-      }
-      if (StringUtils.isNotBlank(send_password)) {
-         setAttribute(request, "sendMessage", send_password);
-         template = "login/send_password.jsp";
-      }
-      doInclude("view", template, request, response);
-   }
-   
-   protected String getEmailBody(String emailText,ActionRequest request,
-         Authentication authentication, Person person) {
-      super.DEFAULT_EMAIL_CONFIRM_TEMPLATE = EMAIL_TEMPLATE_DIR;
-      return String.format(emailText == 
null?getConfirmationTemplate():emailText, authentication
-            .getUserId(), authentication.getPassword(), person.getFirstName(),
-            person.getInfix(), person.getLastName());
-   }
-
-}
+/*
+
+ This software is OSI Certified Open Source Software.
+ OSI Certified is a certification mark of the Open Source Initiative.
+
+ The license (Mozilla version 1.0) can be read at the MMBase site.
+ See http://www.MMBase.org/license
+
+ */
+package com.finalist.cmsc.portlets;
+
+import java.io.IOException;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletSession;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import net.sf.mmapps.modules.cloudprovider.CloudProviderFactory;
+import com.finalist.cmsc.login.PasswordGenerator;
+import com.finalist.cmsc.navigation.NavigationUtil;
+import com.finalist.cmsc.services.community.ApplicationContextFactory;
+import com.finalist.cmsc.services.community.Community;
+import com.finalist.cmsc.services.community.person.Person;
+import com.finalist.cmsc.services.community.person.PersonService;
+import com.finalist.cmsc.services.community.person.RegisterStatus;
+import com.finalist.cmsc.services.community.security.Authentication;
+import com.finalist.cmsc.services.community.security.AuthenticationService;
+import com.finalist.cmsc.util.EmailSender;
+import org.mmbase.bridge.Cloud;
+
+/**
+ * Login portlet
+ *
+ * @author Remco Bos
+ */
+public class LoginPortlet extends AbstractLoginPortlet {
+   
+   public static final String ERRORMESSAGE = "errormessage";
+
+   protected static final String ACTION_PARAMETER = "action";
+
+   protected static final String ACEGI_SECURITY_FORM_USERNAME_KEY = 
"j_username";
+   protected static final String ACEGI_SECURITY_FORM_PASSWORD_KEY = 
"j_password";
+   protected static final String EMAIL_TEMPLATE_DIR = 
"/WEB-INF/templates/view/login/forgotpassword.txt";
+   
+   protected static final String SEND_PASSWORD = "send_password";
+
+   protected static final Log log = LogFactory.getLog(LoginPortlet.class);
+   
+   protected void doEditDefaults(RenderRequest req, RenderResponse res) throws 
IOException,
+   PortletException {
+      super.DEFAULT_EMAIL_CONFIRM_TEMPLATE = EMAIL_TEMPLATE_DIR;
+      super.doEditDefaults(req, res);
+   }
+   
+   @Override
+   public void processView(ActionRequest request, ActionResponse response) 
throws PortletException, IOException {
+      String action = request.getParameter(ACTION_PARAMETER);
+      PortletPreferences preferences = request.getPreferences();
+      
+      if ("login".equals(action)) {
+         String userName = 
request.getParameter(ACEGI_SECURITY_FORM_USERNAME_KEY);
+         String password = 
request.getParameter(ACEGI_SECURITY_FORM_PASSWORD_KEY);
+         String send_password =  request.getParameter(SEND_PASSWORD);
+         
+         if (StringUtils.isEmpty(send_password)) {
+            
+            if (StringUtils.isNotBlank(userName) && 
StringUtils.isNotBlank(password)) {
+               Community.login(userName, password);
+            } else {
+               if (StringUtils.isBlank(userName)) {
+                  response.setRenderParameter(ERRORMESSAGE, 
"register.email.empty");
+               } else {
+                  response.setRenderParameter(ERRORMESSAGE, 
"register.password.empty");
+               }
+
+               return; //Because one of the required fields are empty, there 
is nothing to check anymore
+            }
+            
+            if (Community.isAuthenticated()) {
+               request.getPortletSession().setAttribute("username", userName, 
PortletSession.APPLICATION_SCOPE);
+               String pageid = preferences.getValue(PAGE, null);
+               if (StringUtils.isNotEmpty(pageid)) {
+                  Cloud cloud = 
CloudProviderFactory.getCloudProvider().getCloud();
+                  String redirectUrl = 
NavigationUtil.getNavigationItemUrl((HttpServletRequest)request, 
(HttpServletResponse)response, cloud.getNode(Integer.valueOf(pageid)));
+                  response.sendRedirect(redirectUrl);
+               }
+               log.info(String.format("Login successful for user %s", 
userName));
+            } else {
+               
+               PersonService personHibernateService = (PersonService) 
ApplicationContextFactory.getBean("personService");
+               Person person = 
personHibernateService.getPersonByUserId(userName);
+               
+               if (person != null && 
RegisterStatus.UNCONFIRMED.getName().equalsIgnoreCase(person.getActive())) {
+                  response.setRenderParameter(ERRORMESSAGE, 
"view.account.unconfirmed");
+               }
+               else if (person != null && 
RegisterStatus.BLOCKED.getName().equalsIgnoreCase(person.getActive())) {
+                  response.setRenderParameter(ERRORMESSAGE, 
"view.account.blocked");
+               } else {
+                  log.info(String.format("Login failed for user %s", 
userName));
+                  response.setRenderParameter(ERRORMESSAGE, "login.failed");
+               }
+            }
+         }
+         else {
+            response.setRenderParameter(SEND_PASSWORD, "send");
+         }
+      } else if ("logout".equals(action)) {
+         request.getPortletSession().removeAttribute("username", 
PortletSession.APPLICATION_SCOPE);
+         Community.logout();
+         
+      } else if ("send_password".equals(action)) {
+         //TODO  send password
+         String email =  request.getParameter("username");
+         String sendMessage = "view.account.success";
+         AuthenticationService authenticationService = (AuthenticationService) 
ApplicationContextFactory
+         .getBean("authenticationService");
+         PersonService personHibernateService = (PersonService) 
ApplicationContextFactory.getBean("personService");
+
+         if (authenticationService.authenticationExists(email)) {
+            Person person = personHibernateService.getPersonByUserId(email);
+            Authentication authentication = 
authenticationService.findAuthentication(email);
+           
if(RegisterStatus.ACTIVE.getName().equalsIgnoreCase(person.getActive()) || 
RegisterStatus.UNCONFIRMED.getName().equalsIgnoreCase(person.getActive()))
+           {
+              //todo reset password and send mail 
+              PasswordGenerator generator = new PasswordGenerator();
+              String newPassword = null;
+              try {
+                 newPassword = 
generator.generate(PasswordGenerator.PRINTABLE_CHARACTERS, 7);
+                 authenticationService.updateAuthentication(email, 
authentication.getPassword(), newPassword);
+                 authentication.setPassword(newPassword);
+                 String emailSubject = 
preferences.getValue(EMAIL_SUBJECT,"Your account details associated with the 
given email address.\n");
+                 String emailText = preferences.getValue(EMAIL_TEXT, null);
+                 String emailFrom = preferences.getValue(EMAIL_FROMEMAIL, 
null);
+                 String nameFrom = preferences.getValue(EMAIL_FROMNAME, null);
+                 emailText = getEmailBody(emailText,request, authentication, 
person);
+                 if (StringUtils.isNotBlank(emailFrom) && 
!isEmailAddress(emailFrom)) {
+                    throw new AddressException("Email address '" + emailFrom + 
"' is not available");
+                 }
+                 EmailSender.sendEmail(emailFrom, nameFrom, email, 
emailSubject, emailText,
+                             email, "text/plain;charset=utf-8");
+                 sendMessage = "view.account.success";
+              } 
+              catch (AddressException e) {
+                 log.error("Email address incorrect",e);
+              } 
+              catch (MessagingException e) {
+                 log.error("Email MessagingException",e);
+              }
+              catch (Exception e) {
+                 log.error(e);
+              } 
+           }
+           else if 
(RegisterStatus.BLOCKED.getName().equalsIgnoreCase(person.getActive())){
+              sendMessage = "view.account.blocked"; 
+           }
+         } 
+         else {
+            //log.info("add authenticationId failed");
+            sendMessage = "view.account.notexist"; 
+         }
+         response.setRenderParameter(SEND_PASSWORD, sendMessage);
+      } 
+      else {
+         // Unknown
+         log.error(String.format("Unknown action '%s'", action));
+      }
+   }
+
+   @Override
+   protected void doView(RenderRequest request, RenderResponse response) 
throws PortletException, IOException {
+      
+      String template;
+      String error = request.getParameter(ERRORMESSAGE);
+      String send_password = request.getParameter(SEND_PASSWORD);
+      PortletPreferences preferences = request.getPreferences();
+      String registrationpagepath = preferences.getValue(REGISTRATIONPAGEPATH, 
null);
+      if(StringUtils.isNotEmpty(registrationpagepath)){
+         request.setAttribute(REGISTRATIONPAGEPATH, registrationpagepath);
+      }
+      if (StringUtils.isNotBlank(error)) {
+         request.setAttribute(ERRORMESSAGE, error);
+      }
+      if (Community.isAuthenticated()) {
+         template = "login/logout.jsp";
+      } else {
+         template = "login/login.jsp";
+      }
+      if (StringUtils.isNotBlank(send_password)) {
+         setAttribute(request, "sendMessage", send_password);
+         template = "login/send_password.jsp";
+      }
+      doInclude("view", template, request, response);
+   }
+   
+   protected String getEmailBody(String emailText, ActionRequest request, 
Authentication authentication, Person person) {
+      super.DEFAULT_EMAIL_CONFIRM_TEMPLATE = EMAIL_TEMPLATE_DIR;
+      return String.format(emailText == 
null?getConfirmationTemplate():emailText, authentication
+            .getUserId(), authentication.getPassword(), person.getFirstName(),
+            person.getInfix(), person.getLastName());
+   }
+
+}

Modified: 
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/RegisterPortlet.java
===================================================================
--- 
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/RegisterPortlet.java
    2009-06-05 09:50:24 UTC (rev 35754)
+++ 
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/RegisterPortlet.java
    2009-06-05 09:50:26 UTC (rev 35755)
@@ -197,7 +197,6 @@
       
       Map<String, String> errorMessages = (HashMap<String, String>) 
portletSession.getAttribute(ERRORMESSAGES);
       
-      
       String email = request.getParameter("email");
       String active = request.getParameter("active");
       
@@ -237,6 +236,7 @@
        String lastName = 
request.getParameter(ACEGI_SECURITY_FORM_LASTNAME_KEY);
        String passwordText = 
request.getParameter(ACEGI_SECURITY_FORM_PASSWORD_KEY);
        String passwordConfirmation = 
request.getParameter(ACEGI_SECURITY_FORM_PASSWORDCONF_KEY);
+
       if (StringUtils.isBlank(firstName)) {
          errorMessages.put(ACEGI_SECURITY_FORM_FIRSTNAME_KEY, 
"register.firstname.empty");
       }

Modified: 
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/UnregisterPortlet.java
===================================================================
--- 
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/UnregisterPortlet.java
  2009-06-05 09:50:24 UTC (rev 35754)
+++ 
CMSContainer/branches/b1_6/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/UnregisterPortlet.java
  2009-06-05 09:50:26 UTC (rev 35755)
@@ -28,44 +28,42 @@
    private static final String REMOVE_SUCCESS = "removeSuccess";
    protected static final String EMAIL_REGISTER = "registerEmail";
    protected static final String ERRORMESSAGES = "errormessages";
-   protected void doEditDefaults(RenderRequest req, RenderResponse res) throws 
IOException,
-   PortletException {
+
+   protected void doEditDefaults(RenderRequest req, RenderResponse res) throws 
IOException, PortletException {
       PortletPreferences preferences = req.getPreferences();
-      setAttribute(req, CONFIRMATION_TEXT, 
preferences.getValue(CONFIRMATION_TEXT,""));
+      setAttribute(req, CONFIRMATION_TEXT, 
preferences.getValue(CONFIRMATION_TEXT, ""));
       super.doEditDefaults(req, res);
    }
+
    @Override
-   public void processEditDefaults(ActionRequest request,
-         ActionResponse response) throws PortletException, IOException {
+   public void processEditDefaults(ActionRequest request, ActionResponse 
response) throws PortletException, IOException {
       PortletPreferences preferences = request.getPreferences();
       String portletId = 
preferences.getValue(PortalConstants.CMSC_OM_PORTLET_ID, null);
       if (portletId != null) {
          setPortletParameter(portletId, CONFIRMATION_TEXT, 
request.getParameter(CONFIRMATION_TEXT));
       }
       super.processEditDefaults(request, response);
-      }
+   }
+
    @Override
    public void processView(ActionRequest request, ActionResponse response) 
throws PortletException, IOException {
       PortletPreferences preferences = request.getPreferences();
       String register_email = request.getParameter(EMAIL_REGISTER);
-      
+
       Map<String, String> errorMessages = new HashMap<String, String>();
       if (StringUtils.isBlank(register_email)) {
          errorMessages.put(EMAIL_REGISTER, REGISTER_EMAIL_EMPTY);
       } else if (!isEmailAddress(register_email)) {
          errorMessages.put(EMAIL_REGISTER, REGISTER_EMAIL_MATCH);
       }
-      AuthenticationService authenticationService = (AuthenticationService) 
ApplicationContextFactory
-      .getBean("authenticationService");
+      AuthenticationService authenticationService = (AuthenticationService) 
ApplicationContextFactory.getBean("authenticationService");
       PersonService personHibernateService = (PersonService) 
ApplicationContextFactory.getBean("personService");
-
       if (authenticationService.authenticationExists(register_email)) {
-        Long authId = 
authenticationService.getAuthenticationIdForUserId(register_email);
-        personHibernateService.deletePersonByAuthenticationId(authId);
-        authenticationService.deleteAuthentication(authId);
-        CommunityManager.notify(authId);
-      }
-      else {
+         Long authId = 
authenticationService.getAuthenticationIdForUserId(register_email);
+         personHibernateService.deletePersonByAuthenticationId(authId);
+         authenticationService.deleteAuthentication(authId);
+         CommunityManager.notify(authId);
+      } else {
          errorMessages.put(EMAIL_REGISTER, USER_ACCOUNT_NOTEXIST);
       }
       if (errorMessages.size() > 0) {
@@ -75,6 +73,7 @@
       request.getPortletSession().setAttribute(REMOVE_SUCCESS, 
"unregister.success");
       request.getPortletSession().setAttribute(CONFIRMATION_TEXT, 
preferences.getValue(CONFIRMATION_TEXT, null));
    }
+
    @Override
    protected void doView(RenderRequest request, RenderResponse response) 
throws PortletException, IOException {
       String template = "login/unregister.jsp";
@@ -87,12 +86,12 @@
          request.setAttribute(ERRORMESSAGES, errorMessages);
          request.setAttribute(EMAIL_REGISTER, registerEmail);
       }
-      if(portletSession.getAttribute(REMOVE_SUCCESS) != null) {
+      if (portletSession.getAttribute(REMOVE_SUCCESS) != null) {
          String remove_success = (String) 
portletSession.getAttribute(REMOVE_SUCCESS);
          portletSession.removeAttribute(REMOVE_SUCCESS);
          request.setAttribute(REMOVE_SUCCESS, remove_success);
       }
-      if(portletSession.getAttribute(CONFIRMATION_TEXT) != null) {
+      if (portletSession.getAttribute(CONFIRMATION_TEXT) != null) {
          String confirmation_text = (String) 
portletSession.getAttribute(CONFIRMATION_TEXT);
          portletSession.removeAttribute(CONFIRMATION_TEXT);
          request.setAttribute("confirmText", confirmation_text);

_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to