Update of
/var/cvs/contributions/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets
In directory
james.mmbase.org:/tmp/cvs-serv30145/portlets-login/src/java/com/finalist/cmsc/portlets
Modified Files:
Tag: b1_5
LoginPortlet.java RegisterPortlet.java
Log Message:
CMSC-1320 - Registration portlet: made more error proof, added checks and
improved logic.
See also:
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets
See also: http://www.mmbase.org/jira/browse/CMSC-1320
Index: LoginPortlet.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/LoginPortlet.java,v
retrieving revision 1.11.2.4
retrieving revision 1.11.2.5
diff -u -b -r1.11.2.4 -r1.11.2.5
--- LoginPortlet.java 4 Feb 2009 12:16:29 -0000 1.11.2.4
+++ LoginPortlet.java 5 Mar 2009 14:26:57 -0000 1.11.2.5
@@ -98,8 +98,7 @@
String sendMessage = "view.account.success";
AuthenticationService authenticationService = (AuthenticationService)
ApplicationContextFactory
.getBean("authenticationService");
- PersonService personHibernateService = (PersonService)
ApplicationContextFactory
- .getBean("personService");
+ PersonService personHibernateService = (PersonService)
ApplicationContextFactory.getBean("personService");
if (authenticationService.authenticationExists(email)) {
Person person = personHibernateService.getPersonByUserId(email);
Index: RegisterPortlet.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Portlets/portlets-login/src/java/com/finalist/cmsc/portlets/RegisterPortlet.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -b -r1.1.2.3 -r1.1.2.4
--- RegisterPortlet.java 5 Mar 2009 13:32:45 -0000 1.1.2.3
+++ RegisterPortlet.java 5 Mar 2009 14:26:57 -0000 1.1.2.4
@@ -2,7 +2,7 @@
import java.io.IOException;
import java.util.Date;
-import java.util.Hashtable;
+import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
@@ -86,10 +86,10 @@
@Override
public void processView(ActionRequest request, ActionResponse response)
throws PortletException, IOException {
- Map<String, String> errorMessages = new Hashtable<String, String>();
+ Map<String, String> errorMessages = new HashMap<String, String>();
PortletPreferences preferences = request.getPreferences();
- String email =
request.getParameter(ACEGI_SECURITY_FORM_EMAIL_KEY).trim();
+ String emailTo =
request.getParameter(ACEGI_SECURITY_FORM_EMAIL_KEY).trim();
String firstName =
request.getParameter(ACEGI_SECURITY_FORM_FIRSTNAME_KEY);
String infix = request.getParameter(ACEGI_SECURITY_FORM_INFIX_KEY);
String lastName = request.getParameter(ACEGI_SECURITY_FORM_LASTNAME_KEY);
@@ -98,20 +98,22 @@
Long authId = null;
- if (StringUtils.isBlank(email)) {
+ if (StringUtils.isBlank(emailTo)) {
errorMessages.put(ACEGI_SECURITY_FORM_EMAIL_KEY,
"register.email.empty");
- } else if (!isEmailAddress(email)) {
+ } else if (!isEmailAddress(emailTo)) {
errorMessages.put(ACEGI_SECURITY_FORM_EMAIL_KEY,
"register.email.match");
}
validateInputFields(request, errorMessages, preferences, firstName,
lastName, passwordText, passwordConfirmation);
+ if (errorMessages.isEmpty()) { //Only continue with Community checks,
when there are no other errors yet.
+
AuthenticationService authenticationService = (AuthenticationService)
ApplicationContextFactory.getBean("authenticationService");
PersonService personHibernateService = (PersonService)
ApplicationContextFactory.getBean("personService");
- Long authenticationId =
authenticationService.getAuthenticationIdForUserId(email);
+ Long authenticationId =
authenticationService.getAuthenticationIdForUserId(emailTo);
if (authenticationId == null) {
- Authentication authentication =
authenticationService.createAuthentication(email, passwordText);
+ Authentication authentication =
authenticationService.createAuthentication(emailTo, passwordText);
if (authentication.getId() != null) {
authId = authentication.getId();
@@ -121,7 +123,7 @@
if (lastName == null) lastName = "";
Person person = personHibernateService.createPerson(firstName,
infix, lastName, authId, RegisterStatus.UNCONFIRMED.getName(), new Date());
- person.setEmail(email);
+ person.setEmail(emailTo);
personHibernateService.updatePerson(person);
String groupName = preferences.getValue(GROUPNAME, null);
@@ -132,27 +134,38 @@
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);
+ String nameFrom = preferences.getValue(EMAIL_FROMNAME, "Senders
Name"); //Add default name
emailText = getEmailBody(emailText, request, authentication,
person);
try {
if (!isEmailAddress(emailFrom)) {
- throw new AddressException("Email address '" + emailFrom +
"' is not available or working!");
+ errorMessages.put(ACEGI_SECURITY_DEFAULT, "Email address
'" + emailFrom + "' set in the edit_defaults properties is not available or
working!");
+ } else {
+ EmailSender.sendEmail(emailFrom, nameFrom, emailTo,
emailSubject, emailText, emailTo, "text/plain;charset=utf-8");
}
- EmailSender.sendEmail(emailFrom, nameFrom, email, emailSubject,
emailText, email, "text/plain;charset=utf-8");
} catch (AddressException e) {
log.error("Email address failed", e);
+ errorMessages.put(ACEGI_SECURITY_DEFAULT, "One of the email
addresses failed '" + emailFrom + "' or '" + emailTo + "'!");
} catch (MessagingException e) {
log.error("Email MessagingException failed", e);
+ errorMessages.put(ACEGI_SECURITY_DEFAULT, "Sending email
failed, from '" + emailFrom + "' or '" + emailTo + "'!");
+ }
+ if (errorMessages.isEmpty()) {
+ response.setRenderParameter("email", emailTo);
+ } else {
+ //Email could not be sent, but the user is created..should
remove user & authentication
+
personHibernateService.deletePersonByAuthenticationId(authId);
+ authenticationService.deleteAuthentication(authId);
}
- response.setRenderParameter("email", email);
} else {
- log.error("add authenticationId failed");
+ log.error("adding of authenticationId in database failed");
+ errorMessages.put(ACEGI_SECURITY_DEFAULT, "adding of
authenticationId in database failed");
}
} else {
errorMessages.put(ACEGI_SECURITY_DEFAULT, "register.user.exists");
}
+ }
if (errorMessages.size() > 0) {
request.getPortletSession().setAttribute(ERRORMESSAGES,
errorMessages);
@@ -168,7 +181,7 @@
request.setAttribute("page", screenId);
String template;
- Map<String, String> errorMessages = (Map<String, String>)
portletSession.getAttribute(ERRORMESSAGES);
+ Map<String, String> errorMessages = (HashMap<String, String>)
portletSession.getAttribute(ERRORMESSAGES);
String email = request.getParameter("email");
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs