1 package hero.struts.actions; 2 3 import java.io.IOException ; 4 import javax.servlet.ServletException ; 5 import javax.servlet.http.HttpServletRequest ; 6 import javax.servlet.http.HttpServletResponse ; 7 import org.apache.struts.action.ActionError; 8 import org.apache.struts.action.ActionErrors; 9 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 22 23 public class UserAction extends AbstStrutsActionBase 24 { 25 public boolean authenticate(String username, String password) 26 { 27 return(true); 28 } 29 37 public ActionForward perform(ActionMapping mapping, ActionForm form, 38 HttpServletRequest request, HttpServletResponse response) throws IOException , ServletException 39 { 40 ActionForward actionForward; 41 ActionErrors errors = new ActionErrors(); 43 44 String logged = request.getParameter("user"); 45 actionForward = mapping.findForward(NEWUSER); 46 47 try 48 { 49 if (!isCancelled(request)) 50 { 51 UserForm userForm = (UserForm) form; 52 String name = userForm.getName(); 53 String password = userForm.getPassword(); 54 String email = userForm.getEmail(); 55 String jabber = userForm.getJabber(); 56 57 if (name.length()!=0 && password.length()!=0 && email.length()!=0) 58 { 59 hero.interfaces.UserRegistrationLocalHome userh = (UserRegistrationLocalHome)hero.interfaces.UserRegistrationUtil.getLocalHome(); 60 hero.interfaces.UserRegistrationLocal user = userh.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", "true"); 68 request.getSession(true).setAttribute("newusername", name); 69 } 70 else 71 { 72 errors.add("user_error", new ActionError("error.user.mismatch")); 73 actionForward = mapping.findForward(USERNOTLOGGED); 74 } 75 } 76 else 77 actionForward = mapping.findForward(LOGIN); 78 }catch(Exception e){e.printStackTrace();errors.add("user_error", new ActionError("error.user")); 79 if (logged.equals("notLogged")) 80 actionForward = mapping.findForward(USERNOTLOGGED); 81 else 82 actionForward = mapping.findForward(USER);} 83 84 if (!errors.empty()) { 85 saveErrors(request, errors); 86 } 87 88 return (actionForward); 90 } 91 } 92 | Popular Tags |