1 5 6 package com.raptus.owxv3.pub; 7 8 import java.io.IOException ; 9 10 import javax.servlet.ServletException ; 11 import javax.servlet.http.*; 12 13 import org.apache.struts.action.*; 14 15 import com.raptus.owxv3.*; 16 import com.raptus.owxv3.api.LoginAction; 17 18 41 public class pubLoginAction extends LoginAction 42 { 43 45 60 public ActionForward perform(ActionMapping mapping, 61 ActionForm form, 62 HttpServletRequest request, 63 HttpServletResponse response) 64 throws IOException , ServletException 65 { 66 pubLoginForm owaf = (pubLoginForm) form; 67 String element = request.getParameter(Constants.HTTPGET_PARAM_ELEMENT); 68 if(element == null || element.length() == 0) 69 element = owaf.getElement(); 70 71 if(element != null && element.length() > 0) 72 { 73 if(element.compareToIgnoreCase("login") == 0) { 75 return performLogin(mapping, owaf, request, response); 76 } 77 else if(element.compareToIgnoreCase("logout") == 0) { 79 return performLogout(mapping, owaf, request, response); 80 } 81 } 82 else 83 LoggingManager.log("Unkown element " + element + " requested", this); 84 85 return mapping.findForward(Constants.SCREEN_ERROR_UNKNOWNELEMENT); 86 } 87 88 91 public ActionForward performLogin(ActionMapping mapping, 92 pubLoginForm form, 93 HttpServletRequest request, 94 HttpServletResponse response) 95 throws IOException , ServletException 96 { 97 ActionErrors errors = new ActionErrors(); 98 99 String username = form.getUsername(); 100 String password = form.getPassword(); 101 102 LoggingManager.log("A user <" + username + "> tries to log in.", this); 103 104 String nextView = Constants.SCREEN_LOGIN; 105 if(username != null && password != null) 106 { 107 if(loginUser(request, username, password)) 108 { 109 nextView = Constants.SCREEN_SUCCESS; 110 } 111 else 112 { 113 errors.add("loginerrors", new ActionError(Constants.MESSAGE_I18N_LOGINFAILED)); 114 nextView = Constants.SCREEN_FAILED; 115 } 116 } 117 else 118 { 119 errors.add("loginerrors", new ActionError(Constants.MESSAGE_I18N_LOGINWELCOME)); 120 } 122 123 saveErrors(request, errors); 124 LoggingManager.log("Forwarding user to struts screen <" + nextView + ">", this); 125 LoggingManager.log(errors.size() + " errors during login phase.", this); 126 return mapping.findForward(nextView); 127 } 128 129 132 public ActionForward performLogout(ActionMapping mapping, 133 pubLoginForm form, 134 HttpServletRequest request, 135 HttpServletResponse response) 136 throws IOException , ServletException 137 { 138 XMLConfigManager cm=XMLConfigManager.getInstance(); 142 form.setWebsiteURL( cm.getPropertyByTree("virtualhost","hostname") ); 143 144 HttpSession session = request.getSession(); 145 logoutUser(session); 146 147 return mapping.findForward(Constants.SCREEN_LOGOUT); 148 } 149 150 } 151 152 | Popular Tags |