01: package hero.struts.actions;
02:
03: import java.io.IOException;
04: import javax.servlet.ServletException;
05: import javax.servlet.http.HttpServletRequest;
06: import javax.servlet.http.HttpServletResponse;
07: import org.apache.struts.action.ActionError;
08: import org.apache.struts.action.ActionErrors;
09: import org.apache.struts.action.ActionForm;
10: import org.apache.struts.action.ActionMapping;
11: import org.apache.struts.action.ActionForward;
12:
13: import hero.struts.forms.*;
14: import hero.interfaces.*;
15:
16: /**
17: * <strong>UserAction</strong>
18: * Action that allows the admin to add new users
19: *
20: *@author Miguel Valdes Faura
21: */
22:
23: public class UserAction extends AbstStrutsActionBase {
24: public boolean authenticate(String username, String password) {
25: return (true);
26: }
27:
28: /**
29: * @param mapping The ActionMapping used to select this instance
30: * @param actionForm The optional AbstActionFormBase bean for this request (if any)
31: * @param request The HTTP request we are processing
32: * @param response The HTTP response we are creating
33: * @exception IOException if an input/output error occurs
34: * @exception ServletException if a servlet exception occurs
35: */
36: public ActionForward perform(ActionMapping mapping,
37: ActionForm form, HttpServletRequest request,
38: HttpServletResponse response) throws IOException,
39: ServletException {
40: ActionForward actionForward;
41: // Create the container for any errors that occur
42: ActionErrors errors = new ActionErrors();
43:
44: String logged = request.getParameter("user");
45: actionForward = mapping.findForward(NEWUSER);
46:
47: try {
48: if (!isCancelled(request)) {
49: UserForm userForm = (UserForm) form;
50: String name = userForm.getName();
51: String password = userForm.getPassword();
52: String email = userForm.getEmail();
53: String jabber = userForm.getJabber();
54:
55: if (name.length() != 0 && password.length() != 0
56: && email.length() != 0) {
57: hero.interfaces.UserRegistrationLocalHome userh = (UserRegistrationLocalHome) hero.interfaces.UserRegistrationUtil
58: .getLocalHome();
59: hero.interfaces.UserRegistrationLocal user = userh
60: .create();
61:
62: if (jabber.length() != 0)
63: user.userCreate(name, password, email, jabber);
64: else
65: user.userCreate(name, password, email);
66:
67: request.getSession(true).setAttribute("newuser",
68: "true");
69: request.getSession(true).setAttribute(
70: "newusername", name);
71: } else {
72: errors.add("user_error", new ActionError(
73: "error.user.mismatch"));
74: actionForward = mapping.findForward(USERNOTLOGGED);
75: }
76: } else
77: actionForward = mapping.findForward(LOGIN);
78: } catch (Exception e) {
79: e.printStackTrace();
80: errors.add("user_error", new ActionError("error.user"));
81: if (logged.equals("notLogged"))
82: actionForward = mapping.findForward(USERNOTLOGGED);
83: else
84: actionForward = mapping.findForward(USER);
85: }
86:
87: if (!errors.empty()) {
88: saveErrors(request, errors);
89: }
90:
91: // Forward control to the appropriate URI as determined by the action.
92: return (actionForward);
93: }
94: }
|