1 6 7 package org.contineo.actions; 8 9 import java.util.Locale ; 10 import javax.servlet.http.HttpServletRequest ; 11 import javax.servlet.http.HttpServletResponse ; 12 import javax.servlet.http.HttpSession ; 13 import org.apache.commons.beanutils.BeanUtils; 14 import org.apache.log4j.Level; 15 import org.apache.log4j.Logger; 16 import org.apache.struts.Globals; 17 import org.apache.struts.action.Action; 18 import org.apache.struts.action.ActionError; 19 import org.apache.struts.action.ActionErrors; 20 import org.apache.struts.action.ActionForm; 21 import org.apache.struts.action.ActionForward; 22 import org.apache.struts.action.ActionMapping; 23 import org.contineo.admin.User; 24 import org.contineo.admin.dao.UserDAO; 25 import org.contineo.core.CryptBean; 26 import org.contineo.core.LoggingManager; 27 32 public class LoginAction extends Action { 33 34 38 private Logger logger; 39 40 41 42 public LoginAction() { 43 logger = LoggingManager.getLogger(this.getClass()); 44 } 45 46 49 public ActionForward execute(ActionMapping mapping, 50 ActionForm form, HttpServletRequest request, 51 HttpServletResponse response) { 52 ActionForward actionForward = new ActionForward(); 53 String userName = ""; 55 String password = ""; 56 String language = ""; 57 try { 58 userName = BeanUtils.getSimpleProperty(form, "userName"); 59 password = BeanUtils.getSimpleProperty(form, "password"); 60 language = BeanUtils.getSimpleProperty(form, "language"); 61 } catch (Exception e) { 62 if (logger.isEnabledFor(Level.ERROR)) 63 logger.error(e.getMessage()); 64 } 65 password = CryptBean.cryptString(password); 66 UserDAO userDao = new UserDAO(); 67 if (userDao.validateUser(userName, password)) { 70 if (logger.isEnabledFor(Level.INFO)) 71 logger.info("User " + userName + " logged in."); 72 HttpSession session = request.getSession(true); 73 session.setAttribute("authuser", userName); 74 session.setAttribute("helppage", "index"); 75 session.setAttribute("move", Boolean.valueOf(false)); 76 if (language.equals("default")) { 77 User user = userDao.findByPrimaryKey(userName); 78 language = user.getLanguage(); 79 } 80 session.setAttribute("language", language); 81 Locale locale = new Locale (language, ""); 82 session.setAttribute(Globals.LOCALE_KEY, locale); 83 actionForward = mapping.findForward("login.success"); 84 } else { 85 ActionErrors errors = new ActionErrors(); 86 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("errors.action.password.mismatch")); 87 saveErrors(request,errors); 88 actionForward = mapping.findForward("login"); 89 } 90 return actionForward; 91 } 92 } 93 | Popular Tags |