Update of
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms
In directory
james.mmbase.org:/tmp/cvs-serv10025/community/src/java/com/finalist/cmsc/community/forms
Modified Files:
GroupForm.java UserAddInitAction.java GroupInitAction.java
DeleteGroupAction.java UserForm.java
AbstractCommunityAction.java DeleteUserAction.java
GroupAction.java UserAddAction.java
Log Message:
CMSC-617 Personal Pages module
Synced branch 1.4 fixes to head
See also:
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms
See also: http://www.mmbase.org/jira/browse/CMSC-617
Index: GroupForm.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/GroupForm.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- GroupForm.java 6 Feb 2008 15:10:57 -0000 1.1
+++ GroupForm.java 31 Mar 2008 19:49:01 -0000 1.2
@@ -19,6 +19,10 @@
*/
public class GroupForm extends ActionForm {
+ protected static final String ACTION_ADD = "add";
+
+ protected static final String ACTION_EDIT = "edit";
+
private static final long serialVersionUID = 1L;
private String action;
Index: UserAddInitAction.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/UserAddInitAction.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- UserAddInitAction.java 6 Feb 2008 12:05:14 -0000 1.4
+++ UserAddInitAction.java 31 Mar 2008 19:49:01 -0000 1.5
@@ -22,7 +22,6 @@
import com.finalist.cmsc.services.community.person.PersonService;
import com.finalist.cmsc.services.community.security.Authentication;
import com.finalist.cmsc.services.community.security.AuthenticationService;
-import com.finalist.cmsc.services.community.security.AuthorityService;
/**
* @author Remco Bos
@@ -31,38 +30,41 @@
public class UserAddInitAction extends AbstractCommunityAction {
private static Log log = LogFactory.getLog(UserAddInitAction.class);
+ protected static final String AUTHENTICATION_ID = "authid";
+
public ActionForward execute(ActionMapping actionMapping, ActionForm
actionForm, HttpServletRequest request,
HttpServletResponse httpServletResponse) throws
Exception {
- AuthorityService aus = getAuthorityService();
-
- String id = request.getParameter(USERID);
+ String authId = request.getParameter(AUTHENTICATION_ID);
UserForm userForm = (UserForm) actionForm;
- if (id != null) {
- userForm.setAction(ACTION_EDIT);
+ userForm.clear();
+
+ Authentication auth = null;
AuthenticationService as = getAuthenticationService();
- Authentication auth = as.findAuthentication(id);
+ if (authId != null) {
+ auth = as.getAuthenticationById(Long.valueOf(authId));
+ }
+
if (auth != null) {
- userForm.setEmail(auth.getUserId());
+ userForm.setAction(UserForm.ACTION_EDIT);
+ userForm.setAccount(auth.getUserId());
PersonService ps = getPersonService();
- Person person = ps.getPersonByUserId(id);
- if (person != null) {
-
userForm.setVoornaam(person.getFirstName());
-
userForm.setTussenVoegsels(person.getInfix());
-
userForm.setAchterNaam(person.getLastName());
- } else {
- log.info("person failed");
- }
+ //Returns null when no Person object was found!
+ Person person = ps.getPersonByAuthenticationId(auth.getId());
+ if (person != null) {
+ userForm.setFirstName(person.getFirstName());
+ userForm.setPrefix(person.getInfix());
+ userForm.setLastName(person.getLastName());
+ userForm.setEmail(person.getEmail());
} else {
- log.info("auth failed");
+ log.debug("person failed");
}
-
} else {
// new
- userForm.setAction(ACTION_ADD);
+ userForm.setAction(UserForm.ACTION_ADD);
}
return actionMapping.findForward(SUCCESS);
Index: GroupInitAction.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/GroupInitAction.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- GroupInitAction.java 8 Feb 2008 13:13:28 -0000 1.4
+++ GroupInitAction.java 31 Mar 2008 19:49:01 -0000 1.5
@@ -36,6 +36,8 @@
private static Log log = LogFactory.getLog(GroupInitAction.class);
+ protected static final String GROUPID = "groupid";
+
public ActionForward execute(ActionMapping actionMapping, ActionForm
actionForm, HttpServletRequest request,
HttpServletResponse httpServletResponse) throws
Exception {
@@ -51,7 +53,7 @@
GroupForm groupForm = (GroupForm) actionForm;
if (id != null) {
- groupForm.setAction(ACTION_EDIT);
+ groupForm.setAction(GroupForm.ACTION_EDIT);
Authority auth = aus.findAuthorityByName(id);
if (auth != null) {
groupForm.setName(auth.getName());
@@ -71,7 +73,7 @@
}
} else {
// new
- groupForm.setAction(ACTION_ADD);
+ groupForm.setAction(GroupForm.ACTION_ADD);
groupForm.reset(actionMapping, request);
for (Iterator<Authentication> iter = users.iterator();
iter.hasNext();) {
Authentication user = iter.next();
Index: DeleteGroupAction.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/DeleteGroupAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- DeleteGroupAction.java 6 Feb 2008 13:56:26 -0000 1.1
+++ DeleteGroupAction.java 31 Mar 2008 19:49:01 -0000 1.2
@@ -23,6 +23,8 @@
*/
public class DeleteGroupAction extends AbstractCommunityAction {
+ protected static final String GROUPID = "groupid";
+
public ActionForward execute(ActionMapping actionMapping, ActionForm
actionForm, HttpServletRequest request,
HttpServletResponse httpServletResponse) throws
Exception {
String groupId = request.getParameter(GROUPID);
Index: UserForm.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/UserForm.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- UserForm.java 6 Feb 2008 12:05:14 -0000 1.3
+++ UserForm.java 31 Mar 2008 19:49:01 -0000 1.4
@@ -10,6 +10,7 @@
import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
@@ -20,25 +21,29 @@
*/
public class UserForm extends ActionForm {
+ protected static final String ACTION_ADD = "add";
+
+ protected static final String ACTION_EDIT = "edit";
+
private static final long serialVersionUID = 1L;
private String action;
private String email;
- private String password;
+ private String passwordText;
private String passwordConfirmation;
private String account;
- private String voornaam;
+ private String firstName;
- private String tussenVoegsels;
+ private String prefix;
- private String achterNaam;
+ private String lastName;
- private String bedrijf;
+ private String company;
public String getAction() {
return action;
@@ -56,28 +61,28 @@
this.account = account;
}
- public String getVoornaam() {
- return voornaam;
+ public String getFirstName() {
+ return firstName;
}
- public void setVoornaam(String voornaam) {
- this.voornaam = voornaam;
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
}
- public String getTussenVoegsels() {
- return tussenVoegsels;
+ public String getPrefix() {
+ return prefix;
}
- public void setTussenVoegsels(String tussenVoegsels) {
- this.tussenVoegsels = tussenVoegsels;
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
}
- public String getAchterNaam() {
- return achterNaam;
+ public String getLastName() {
+ return lastName;
}
- public void setAchterNaam(String achterNaam) {
- this.achterNaam = achterNaam;
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
}
public String getEmail() {
@@ -88,20 +93,20 @@
this.email = email;
}
- public String getBedrijf() {
- return bedrijf;
+ public String getCompany() {
+ return company;
}
- public void setBedrijf(String bedrijf) {
- this.bedrijf = bedrijf;
+ public void setBedrijf(String company) {
+ this.company = company;
}
- public String getPassword() {
- return password;
+ public String getPasswordText() {
+ return passwordText;
}
- public void setPassword(String password) {
- this.password = password;
+ public void setPasswordText(String passwordText) {
+ this.passwordText = passwordText;
}
public String getPasswordConfirmation() {
@@ -114,19 +119,49 @@
public ActionErrors validate(ActionMapping actionMapping,
HttpServletRequest httpServletRequest) {
ActionErrors actionErrors = new ActionErrors();
+ if (account.equals("")) {
+ actionErrors.add("account", new
ActionMessage("userform.account.empty"));
+ }
if (email.equals("")) {
- actionErrors.add("email", new
ActionMessage("email.empty"));
+ actionErrors.add("email", new
ActionMessage("userform.email.empty"));
}
- if (password.equals("")) {
- actionErrors.add("password", new
ActionMessage("password.empty"));
+ if (this.getAction().equalsIgnoreCase(ACTION_ADD)){
+ validatePassword(actionErrors);
+ } else {
+ if (this.getAction().equalsIgnoreCase(ACTION_EDIT)){
+ if (!StringUtils.isBlank(passwordText) ||
!StringUtils.isBlank(passwordConfirmation)){
+ validatePassword(actionErrors);
}
- if (passwordConfirmation.equals("")) {
- actionErrors.add("passwordConfirmation", new
ActionMessage("passwordConfirmation.empty"));
}
- if (!password.equals("") && !passwordConfirmation.equals("") &&
!password.equals(passwordConfirmation)) {
- actionErrors.add("password", new
ActionMessage("passwords.not_equal"));
}
return actionErrors;
}
+ public void validatePassword(ActionErrors actionErrors) {
+ //Only check this if an user is added
+ if (StringUtils.isBlank(passwordText)) {
+ actionErrors.add("password", new
ActionMessage("userform.password.empty"));
+ }
+ if (StringUtils.isBlank(passwordConfirmation)) {
+ actionErrors.add("passwordConfirmation", new
ActionMessage("userform.password.empty"));
+ }
+ if (!StringUtils.isBlank(passwordText)
+ && !StringUtils.isBlank(passwordConfirmation)
+ && !passwordText.equals(passwordConfirmation)) {
+ actionErrors.add("password", new
ActionMessage("userform.passwords.not_equal"));
+ }
+ }
+
+ public void clear() {
+ action = null;
+ email = null;
+ passwordText = null;
+ passwordConfirmation = null;
+ account = null;
+ firstName = null;
+ prefix = null;
+ lastName = null;
+ company = null;
+ }
+
}
Index: AbstractCommunityAction.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/AbstractCommunityAction.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- AbstractCommunityAction.java 22 Feb 2008 12:36:35 -0000 1.6
+++ AbstractCommunityAction.java 31 Mar 2008 19:49:01 -0000 1.7
@@ -28,18 +28,10 @@
*/
public class AbstractCommunityAction extends ActionSupport {
- protected static final String ACTION_ADD = "add";
-
- protected static final String ACTION_EDIT = "edit";
-
protected static final String SUCCESS = "success";
protected static final String CANCEL = "cancel";
- protected static final String USERID = "userid";
-
- protected static final String GROUPID = "groupid";
-
protected AuthenticationService getAuthenticationService() {
WebApplicationContext ctx = getWebApplicationContext();
return (AuthenticationService)
ctx.getBean("authenticationService");
Index: DeleteUserAction.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/DeleteUserAction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- DeleteUserAction.java 31 Jan 2008 13:48:20 -0000 1.3
+++ DeleteUserAction.java 31 Mar 2008 19:49:01 -0000 1.4
@@ -3,6 +3,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
@@ -14,13 +15,16 @@
*/
public class DeleteUserAction extends AbstractCommunityAction {
+ protected static final String AUTHENTICATION_ID = "authid";
+
@Override
public ActionForward execute(ActionMapping mapping, ActionForm
actionForm, HttpServletRequest request,
HttpServletResponse httpServletResponse) throws
Exception {
- String userId = request.getParameter(USERID);
- if (userId != null) {
- getPersonService().deletePersonByUserId(userId);
- getAuthenticationService().deleteAuthentication(userId);
+ String authenticationId =
request.getParameter(AUTHENTICATION_ID);
+ if (!StringUtils.isBlank(authenticationId)) {
+ Long authId = Long.valueOf(authenticationId);
+ getPersonService().deletePersonByAuthenticationId(authId);
+ getAuthenticationService().deleteAuthentication(authId);
}
return mapping.findForward(SUCCESS);
}
Index: GroupAction.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/GroupAction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- GroupAction.java 8 Feb 2008 15:36:16 -0000 1.3
+++ GroupAction.java 31 Mar 2008 19:49:01 -0000 1.4
@@ -7,8 +7,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
@@ -25,8 +23,6 @@
*/
public class GroupAction extends AbstractCommunityAction {
- private static Log log = LogFactory.getLog(GroupAction.class);
-
public ActionForward execute(ActionMapping actionMapping, ActionForm
actionForm, HttpServletRequest request,
HttpServletResponse httpServletResponse) throws
Exception {
@@ -64,7 +60,7 @@
// validate
ActionMessages errors = new ActionMessages();
- if (groupForm.getAction().equalsIgnoreCase(ACTION_ADD))
{
+ if
(groupForm.getAction().equalsIgnoreCase(GroupForm.ACTION_ADD)) {
if (id == null || id.length() < 3) {
errors.add("groupname", new
ActionMessage("error.groupname.invalid"));
saveErrors(request, errors);
Index: UserAddAction.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/UserAddAction.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- UserAddAction.java 6 Feb 2008 12:05:14 -0000 1.4
+++ UserAddAction.java 31 Mar 2008 19:49:01 -0000 1.5
@@ -11,18 +11,20 @@
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 org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
+import com.finalist.cmsc.services.community.person.Person;
import com.finalist.cmsc.services.community.person.PersonService;
+import com.finalist.cmsc.services.community.security.Authentication;
import com.finalist.cmsc.services.community.security.AuthenticationService;
-import com.finalist.cmsc.services.community.security.AuthorityService;
/**
- * Add a Authentication and Person
+ * Add an Authentication and Person
*
* @author Remco Bos
* @author Wouter Heijke
@@ -31,45 +33,69 @@
private static Log log = LogFactory.getLog(UserAddInitAction.class);
- public ActionForward execute(ActionMapping actionMapping, ActionForm
actionForm, HttpServletRequest httpServletRequest,
- HttpServletResponse httpServletResponse) throws
Exception {
+ @Override
+ public ActionForward execute(ActionMapping actionMapping, ActionForm
actionForm, HttpServletRequest httpServletRequest, HttpServletResponse
httpServletResponse)
+ throws Exception {
if (!isCancelled(httpServletRequest)) {
UserForm userForm = (UserForm) actionForm;
- String id = userForm.getEmail();
+ // String accountName = userForm.getEmail();
+ String accountName = userForm.getAccount();
- AuthorityService aus = getAuthorityService();
+ // AuthorityService aus = getAuthorityService(); //Never used (yet).
AuthenticationService as = getAuthenticationService();
PersonService ps = getPersonService();
- if (userForm.getAction().equalsIgnoreCase(ACTION_ADD)) {
- Long check1 =
as.getAuthenticationIdForUserId(id);
- if (check1 == null) {
-
as.createAuthentication(userForm.getEmail(), userForm.getPassword());
- Long check2 =
as.getAuthenticationIdForUserId(id);
- if (check2 != null) {
-
ps.createPerson(userForm.getVoornaam(), userForm.getTussenVoegsels(),
userForm.getAchterNaam(), id);
+ if (userForm.getAction().equalsIgnoreCase(UserForm.ACTION_ADD)) {
+ Long authenticationId =
as.getAuthenticationIdForUserId(accountName);
+ if (authenticationId == null) {
+ Authentication authentication =
as.createAuthentication(userForm.getEmail(), userForm.getPasswordText());
+ // Long authenticationId =
+ // as.getAuthenticationIdForUserId(accountName);
+ if (authentication.getId() != null) {
+ Person person = ps.createPerson(userForm.getFirstName(),
userForm.getPrefix(), userForm.getLastName(), authentication.getId());
+ person.setEmail(userForm.getEmail()); // Also add an email
address to the user.
+ ps.updatePerson(person);
+
} else {
- log.info("add check2 failed");
+ log.info("add authenticationId failed");
}
} else {
- log.info("add check1 failed for: " +
id);
+ log.info("add check1 failed for: " + accountName);
}
- } else if
(userForm.getAction().equalsIgnoreCase(ACTION_EDIT)) {
- Long check1 =
as.getAuthenticationIdForUserId(id);
- if (check1 != null) {
- String newPassword1 =
userForm.getPassword();
+ } else if
(userForm.getAction().equalsIgnoreCase(UserForm.ACTION_EDIT)) {
+ Long authenticationId =
as.getAuthenticationIdForUserId(accountName);
+ if (authenticationId != null) {
+ String newPassword1 = userForm.getPasswordText();
String newPassword2 =
userForm.getPasswordConfirmation();
- if (newPassword1 != null &&
newPassword2 != null) {
- if
(newPassword1.equalsIgnoreCase(newPassword2)) {
-
as.updateAuthenticationPassword(id, newPassword1);
+ if (!StringUtils.isBlank(newPassword1) &&
!StringUtils.isBlank(newPassword2)) {
+ if (newPassword1.equals(newPassword2)) {
+ as.updateAuthenticationPassword(accountName,
newPassword1);
+ }
}
+
+ // First retrieve the right person object from the database
+ Person person =
ps.getPersonByAuthenticationId(authenticationId);
+
+ if (person == null) { // User did not exists, so create it.
+ person = new Person();
+ person.setAuthenticationId(authenticationId);
}
+ // Also save other fields entered in the form to the right
person
+ // object
+ person.setFirstName(userForm.getFirstName());
+ person.setInfix(userForm.getPrefix());
+ person.setLastName(userForm.getLastName());
+ person.setEmail(userForm.getEmail());
+
+ // Store the new person data to the database again.
+ ps.updatePerson(person);
+
} else {
- log.info("edit check1 failed for: " +
id);
+ log.info("edit check1 failed for: " + accountName);
}
} else {
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs