Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/acs/damsel/client/add/RegisterNewUserAction.java


1   package org.acs.damsel.client.add;
2   
3   import org.apache.struts.action.*;
4   import javax.servlet.http.*;
5   import org.acs.damsel.srvr.user.*;
6   import org.acs.damsel.client.ClientApp;
7   import java.sql.*;
8   
9   public class RegisterNewUserAction
10      extends Action {
11    public ActionForward execute(ActionMapping actionMapping,
12                                 ActionForm actionForm,
13                                 HttpServletRequest httpServletRequest,
14                                 HttpServletResponse httpServletResponse) {
15  
16      RegisterNewUserForm registerNewUserForm = (RegisterNewUserForm) actionForm;
17      String userName = registerNewUserForm.getUserName();
18      String password1 = registerNewUserForm.getPassword1();
19      String password2 = registerNewUserForm.getPassword2();
20      String firstName = registerNewUserForm.getFirstName();
21      String lastName = registerNewUserForm.getLastName();
22      String middleInitial = registerNewUserForm.getMiddleInitial();
23      String email = registerNewUserForm.getEmail();
24      String organization = registerNewUserForm.getOrganization();
25  
26      ActionErrors errors;
27  
28      /*Check for blank user */
29      if (userName.trim().equals("")) {
30        errors = new ActionErrors();
31        errors.add("register", new ActionError("username.not.given"));
32        this.saveErrors(httpServletRequest, errors);
33        return actionMapping.findForward("refresh");
34      }
35  
36      /*Check for blank password(s) */
37      if (password1.trim().equals("") || password2.trim().equals("")) {
38        errors = new ActionErrors();
39        errors.add("register", new ActionError("password.not.given"));
40        this.saveErrors(httpServletRequest, errors);
41        return actionMapping.findForward("refresh");
42      }
43  
44      /*Check for non-matching password(s) */
45      if (!password1.equals(password2)) {
46        errors = new ActionErrors();
47        errors.add("register", new ActionError("passwords.dont.match"));
48        this.saveErrors(httpServletRequest, errors);
49        return actionMapping.findForward("refresh");
50      }
51  
52      /*Check for blank first name */
53     if (firstName.trim().equals("")) {
54       errors = new ActionErrors();
55       errors.add("register", new ActionError("firstname.not.given"));
56       this.saveErrors(httpServletRequest, errors);
57       return actionMapping.findForward("refresh");
58     }
59  
60     /*Check for blank last name */
61     if (lastName.trim().equals("")) {
62       errors = new ActionErrors();
63       errors.add("register", new ActionError("lastname.not.given"));
64       this.saveErrors(httpServletRequest, errors);
65       return actionMapping.findForward("refresh");
66     }
67  
68      /*Check for blank email */
69     if (email.trim().equals("")) {
70       errors = new ActionErrors();
71       errors.add("register", new ActionError("email.not.given"));
72       this.saveErrors(httpServletRequest, errors);
73       return actionMapping.findForward("refresh");
74     }
75  
76     /*Add the user!! */
77     User user = new User();
78     user.setUserName(userName);
79     user.setPassword(password1);
80     user.setFirstName(firstName);
81     user.setLastName(lastName);
82     user.setMiddleInitial(middleInitial);
83     user.setEmail(email);
84     user.setOrganization(organization);
85    try {
86     int affected = ClientApp.instance().getUserMgr().addUser(user);
87     ClientApp.instance().getGroupMgr().addUserToGroup(user.getUserName(), "Users");
88     /*User already exists */
89     if (affected == 0 ) {
90       errors = new ActionErrors();
91       errors.add("register", new ActionError("username.already.exists"));
92       this.saveErrors(httpServletRequest, errors);
93       return actionMapping.findForward("refresh");
94     }
95    }
96    catch (SQLException ex) {
97      errors = new ActionErrors();
98       errors.add("register", new ActionError("register.unknown.error"));
99       this.saveErrors(httpServletRequest, errors);
100      return actionMapping.findForward("refresh");
101   }
102     return actionMapping.findForward("success");
103   }
104 }