public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // response.setHeader("Cache-Control","no-cache"); //Forces caches to obtain a new copy of the // page from the origin server // response.setHeader("Cache-Control","no-store"); //Directs caches not to store the page under // any circumstance // response.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale" // response.setHeader("Pragma","no-cache"); //HTTP 1.0 backward compatibility /* if (this.userIsLoggedIn(request)) { //ActionMessages errors_mesg = new ActionMessages(); //errors_mesg.add("submitError", new ActionMessage("errors.login.sessionended")); //this.saveErrors(request, errors_mesg); //return mapping.findForward("sessionEnded"); } */ // request.getSession().invalidate(); boolean action_perform = false; String action_target; UserLogin u = new UserLogin(); ActionMessages errors_mesg = new ActionMessages(); UserForm uf = (UserForm) form; if (form != null) { u.setUsername(uf.getUsername()); u.setPassword(uf.getPassword()); action_perform = u.doLogin(); } if (action_perform == false) { errors_mesg.add("submitError", new ActionMessage("errors.login.fail")); saveErrors(request, errors_mesg); action_target = "failure"; } else { System.out.println("userDetails :: " + uf); request.getSession().setAttribute("userDetails", uf); HttpSession session = request.getSession(); session.setAttribute("logined", "true"); session.setAttribute("context", new java.util.Date()); action_target = "success"; } return mapping.findForward(action_target); }
/** * This is the action called from the Struts framework. * * @param mapping The ActionMapping used to select this instance. * @param form The optional ActionForm bean for this request. * @param request The HTTP Request we are processing. * @param response The HTTP Response we are processing. * @throws java.lang.Exception * @return */ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { UserForm registerationForm = (UserForm) form; ActionMessages errors = new ActionMessages(); String username = registerationForm.getUsername(); String password = registerationForm.getPassword(); String confirmPasswod = registerationForm.getConfirmPassword(); String email = registerationForm.getEmail(); if (!password.equals(confirmPasswod)) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.password.mismatch")); saveErrors(request, errors); return mapping.getInputForward(); } UserManager mgr = new DummyUserManagerImpl(); User user = new User(); user.setEmail(email); user.setUsername(username); user.setPassword(password); try { mgr.registerUser(user); } catch (Exception e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.register.failed")); saveErrors(request, errors); return mapping.getInputForward(); } request.setAttribute("username", username); request.setAttribute("password", password); return mapping.findForward(SUCCESS); }