Update of 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms
In directory 
james.mmbase.org:/tmp/cvs-serv12548/community/src/java/com/finalist/cmsc/community/forms

Modified Files:
      Tag: b1_4
        UserForm.java UserAddInitAction.java UserAddAction.java 
Log Message:
CMSC-830 - Add Send Password functionality and improve Community source code, 
not fully ready, but big steps are made.


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-830


Index: UserForm.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/UserForm.java,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -b -r1.2.2.1 -r1.2.2.2
--- UserForm.java       25 Feb 2008 16:26:17 -0000      1.2.2.1
+++ UserForm.java       21 Mar 2008 16:46:29 -0000      1.2.2.2
@@ -26,19 +26,19 @@
 
        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 +56,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 +88,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() {
@@ -117,13 +117,13 @@
                if (email.equals("")) {
                        actionErrors.add("email", new 
ActionMessage("email.empty"));
                }
-               if (password.equals("")) {
+               if (passwordText.equals("")) {
                        actionErrors.add("password", new 
ActionMessage("password.empty"));
                }
                if (passwordConfirmation.equals("")) {
                        actionErrors.add("passwordConfirmation", new 
ActionMessage("passwordConfirmation.empty"));
                }
-               if (!password.equals("") && !passwordConfirmation.equals("") && 
!password.equals(passwordConfirmation)) {
+               if (!passwordText.equals("") && 
!passwordConfirmation.equals("") && !passwordText.equals(passwordConfirmation)) 
{
                        actionErrors.add("password", new 
ActionMessage("passwords.not_equal"));
                }
                return actionErrors;


Index: UserAddInitAction.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/UserAddInitAction.java,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -u -b -r1.3.2.1 -r1.3.2.2
--- UserAddInitAction.java      25 Feb 2008 16:26:17 -0000      1.3.2.1
+++ UserAddInitAction.java      21 Mar 2008 16:46:29 -0000      1.3.2.2
@@ -34,7 +34,7 @@
        public ActionForward execute(ActionMapping actionMapping, ActionForm 
actionForm, HttpServletRequest request,
                        HttpServletResponse httpServletResponse) throws 
Exception {
 
-               AuthorityService aus = getAuthorityService();
+//             AuthorityService aus = getAuthorityService();
 
                String id = request.getParameter(USERID);
                UserForm userForm = (UserForm) actionForm;
@@ -44,14 +44,16 @@
                        AuthenticationService as = getAuthenticationService();
                        Authentication auth = as.findAuthentication(id);
                        if (auth != null) {
-                               userForm.setEmail(auth.getUserId());
-
                                PersonService ps = getPersonService();
-                               Person person = ps.getPersonByUserId(id);
+                               Person person = ps.getPersonByUserId(id); 
//Returns null when no Person object was found!
+                               userForm.setAccount(id);
+                               
                                if (person != null) {
-                                       
userForm.setVoornaam(person.getFirstName());
-                                       
userForm.setTussenVoegsels(person.getInfix());
-                                       
userForm.setAchterNaam(person.getLastName());
+                                       
userForm.setFirstName(person.getFirstName());
+                                       userForm.setPrefix(person.getInfix());
+                                       
userForm.setLastName(person.getLastName());
+                                       userForm.setEmail(person.getEmail());
+                                       
                                } else {
                                        log.info("person failed");
                                }


Index: UserAddAction.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/UserAddAction.java,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -u -b -r1.3.2.1 -r1.3.2.2
--- UserAddAction.java  25 Feb 2008 16:26:17 -0000      1.3.2.1
+++ UserAddAction.java  21 Mar 2008 16:46:29 -0000      1.3.2.2
@@ -17,12 +17,13 @@
 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
@@ -37,39 +38,65 @@
                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);
+                               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();
+                               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);
+                                                       
as.updateAuthenticationPassword(accountName, newPassword1);
                                                }
                                        }
 
+                                       //First retrieve the right person 
object from the database
+               Person p = new Person();
+               p.setAuthenticationId(authenticationId);
+               Person person = null;
+
+               if (ps.getPerson(p).isEmpty()) { //User did not exists, so 
create it.
+                  person = new Person();
+                  person.setAuthenticationId(authenticationId);
+               } else {
+                  //Update existing Person from database.
+                  person = ps.getPerson(p).get(0); //Retrieve first user found
+               }
+               
+               //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

Reply via email to