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.HttpSession ; 7 import javax.servlet.http.HttpServletResponse ; 8 import org.apache.struts.action.ActionError; 9 import org.apache.struts.action.ActionErrors; 10 import org.apache.struts.action.ActionForm; 11 import org.apache.struts.action.ActionMapping; 12 import org.apache.struts.action.ActionForward; 13 import hero.interfaces.*; 14 15 22 public class LoginAction extends AbstStrutsActionBase 23 { 24 29 public boolean authenticate(String username, String password) 30 { 31 return(true); 32 } 33 34 42 43 public ActionForward perform(ActionMapping mapping, ActionForm form, 44 HttpServletRequest request, HttpServletResponse response) throws IOException , ServletException 45 { 46 ActionForward actionForward = mapping.findForward(LOGIN); 49 ActionErrors errors = new ActionErrors(); 51 52 55 HttpSession session = request.getSession(); 56 String action = (String )session.getAttribute("action"); 57 58 try { 59 60 hero.interfaces.UserSessionLocalHome userh = (UserSessionLocalHome)hero.interfaces.UserSessionUtil.getLocalHome(); 61 hero.interfaces.UserSessionLocal usersession = userh.create(); 62 63 request.getSession(true).setAttribute("username", usersession.getUser()); 64 request.getSession(true).setAttribute("password", usersession.getUserPassword()); 65 request.getSession(true).setAttribute("workElement", "null"); 66 67 if (action.equals("user")) 68 { 69 request.getSession(true).setAttribute("user", usersession); 70 71 String project = (String )session.getAttribute("project"); 72 73 if (project.equals("clone")) 74 { 75 actionForward = mapping.findForward(CLONEPROJECT); 77 } 78 if (project.equals("details")) 79 { 80 actionForward = mapping.findForward(PROJECTDETAILS); 82 } 83 } 84 else 85 { 86 try{ 87 String project = (String )session.getAttribute("projectname"); 88 89 hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome)hero.interfaces.ProjectSessionUtil.getLocalHome(); 90 hero.interfaces.ProjectSessionLocal projectsession = projecth.create(); 91 projectsession.initProject(project); 92 93 if (action.equals("node")) 94 { 95 String name = (String )session.getAttribute("nodename"); 96 String username = (String )session.getAttribute("username"); 97 hero.util.StrutsNodeValue node = projectsession.getStrutsNode(name); 98 request.getSession(true).setAttribute("node", node); 99 100 if (!node.getDeadline().equals("Deadline needed")) 101 { 102 java.sql.Timestamp deadline = java.sql.Timestamp.valueOf(node.getDeadline()+" 00:00:00"); 103 if (deadline.getTime() <= (new java.util.Date ()).getTime() && !node.getState().equals("TERMINATED")); 104 errors.add("deadline_error", new ActionError("error.deadline")); 105 } 106 107 request.getSession(true).setAttribute("project", projectsession); 108 request.getSession(true).setAttribute("proAct", "false"); 109 request.getSession(true).setAttribute("edit", "false"); 110 111 actionForward = mapping.findForward(ACTIVITY); 113 } 114 if (action.equals("project")) 115 { 116 request.getSession(true).setAttribute("project", projectsession); 117 request.getSession(true).setAttribute("proAct", "true"); 118 request.getSession(true).setAttribute("edit", "false"); 119 120 request.getSession(true).setAttribute("nodes", projectsession.getStrutsNodes()); 121 request.getSession(true).setAttribute("edges", projectsession.getStrutsEdges()); 122 123 124 actionForward = mapping.findForward(PROJECT); 126 } 127 }catch(Exception pe){actionForward = mapping.findForward(INITIAL);errors.add("project_error", new ActionError("error.project.mismatch"));} 128 } 129 }catch(Exception e){errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.password.mismatch"));} 130 131 if (!errors.empty()) { 134 saveErrors(request, errors); 135 } 136 137 return (actionForward); 139 } 140 } 141 | Popular Tags |