Author: jkoster
Date: 2009-06-05 11:50:24 +0200 (Fri, 05 Jun 2009)
New Revision: 35754
Modified:
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/AbstractLoginPortlet.java
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/LoginPortlet.java
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/RegisterPortlet.java
CMSContainer/branches/b1_5/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_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/AbstractLoginPortlet.java
===================================================================
---
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/AbstractLoginPortlet.java
2009-06-05 09:50:14 UTC (rev 35753)
+++
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/AbstractLoginPortlet.java
2009-06-05 09:50:24 UTC (rev 35754)
@@ -37,7 +37,7 @@
public abstract class AbstractLoginPortlet extends CmscPortlet{
- protected String DEFAULT_EMAIL_CONFIRM_TEMPLATE =
"../templates/view/login/confirmation.txt";
+ 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";
@@ -47,8 +47,8 @@
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 {
@@ -132,7 +132,7 @@
Node regiesterPortletDefination = portletDefinations.getNode(0);
if (portletDefinations.size() > 1) {
log.error("found " + portletDefinations.size()
- + " regiesterPortlet nodes; first one will be used");
+ + " registerPortlet nodes; first one will be used");
}
NodeList portlets = regiesterPortletDefination.getRelatedNodes("portlet",
"definitionrel", SearchUtil.SOURCE);
@@ -166,12 +166,11 @@
}
protected String getConfirmationTemplate() {
- InputStream is = Thread.currentThread().getContextClassLoader()
- .getResourceAsStream(getEmailConfirmTemplate());
+ InputStream is =
getPortletContext().getResourceAsStream(getEmailConfirmTemplate());
if (is == null) {
- throw new NullPointerException(
- "The confirmation template file confirmation.txt in directory
'templates/view/login' does't exist.");
+ 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));
@@ -184,12 +183,15 @@
}
is.close();
} catch (IOException e) {
- log.error("error happened when reading email template", 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;
}
Modified:
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/LoginPortlet.java
===================================================================
---
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/LoginPortlet.java
2009-06-05 09:50:14 UTC (rev 35753)
+++
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/LoginPortlet.java
2009-06-05 09:50:24 UTC (rev 35754)
@@ -54,7 +54,7 @@
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 EMAIL_TEMPLATE_DIR =
"/WEB-INF/templates/view/login/forgotpassword.txt";
protected static final String SEND_PASSWORD = "send_password";
@@ -148,17 +148,17 @@
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");
+ 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 failed",e);
+ log.error("Email address incorrect",e);
}
catch (MessagingException e) {
- log.error("Email MessagingException failed",e);
+ log.error("Email MessagingException",e);
}
catch (Exception e) {
log.error(e);
@@ -206,8 +206,7 @@
doInclude("view", template, request, response);
}
- protected String getEmailBody(String emailText,ActionRequest request,
- Authentication authentication, Person person) {
+ 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(),
Modified:
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/RegisterPortlet.java
===================================================================
---
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/RegisterPortlet.java
2009-06-05 09:50:14 UTC (rev 35753)
+++
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/RegisterPortlet.java
2009-06-05 09:50:24 UTC (rev 35754)
@@ -21,9 +21,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import com.finalist.cmsc.mmbase.PropertiesUtil;
import com.finalist.cmsc.portalImpl.PortalConstants;
-import com.finalist.cmsc.repository.forms.SearchAction;
import com.finalist.cmsc.services.community.ApplicationContextFactory;
import com.finalist.cmsc.services.community.person.Person;
import com.finalist.cmsc.services.community.person.PersonService;
@@ -36,7 +34,6 @@
public class RegisterPortlet extends AbstractLoginPortlet {
- private static final boolean DEBUG = true;
public static final String ACEGI_SECURITY_FORM_EMAIL_KEY = "email";
public static final String ACEGI_SECURITY_FORM_FIRSTNAME_KEY = "firstName";
public static final String ACEGI_SECURITY_FORM_INFIX_KEY = "infix";
@@ -146,12 +143,7 @@
if (!isEmailAddress(emailFrom)) {
errorMessages.put(ACEGI_SECURITY_DEFAULT, "Email address
'" + emailFrom + "' set in the edit_defaults properties is not available or
working!");
} else {
- Boolean debugMode =
Boolean.valueOf(PropertiesUtil.getProperty("register.debug"));
- if (debugMode) {
- log.warn("DEBUG MODE: sendEmail from: " + emailFrom
+ " to: " + emailTo);
- } else {
EmailSender.sendEmail(emailFrom, nameFrom, emailTo,
emailSubject, emailText, emailTo, "text/plain;charset=utf-8");
- }
}
} catch (AddressException e) {
log.error("Email address failed", e);
Modified:
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/UnregisterPortlet.java
===================================================================
---
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/UnregisterPortlet.java
2009-06-05 09:50:14 UTC (rev 35753)
+++
CMSContainer/branches/b1_5/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/UnregisterPortlet.java
2009-06-05 09:50:24 UTC (rev 35754)
@@ -28,43 +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) {
@@ -74,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";
@@ -86,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