1 package org.nextime.ion.backoffice.action; 2 3 import java.io.IOException ; 4 5 import javax.servlet.ServletException ; 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 import org.apache.struts.action.Action; 9 import org.apache.struts.action.ActionError; 10 import org.apache.struts.action.ActionErrors; 11 import org.apache.struts.action.ActionForm; 12 import org.apache.struts.action.ActionForward; 13 import org.apache.struts.action.ActionMapping; 14 import org.nextime.ion.backoffice.form.LoginForm; 15 import org.nextime.ion.backoffice.security.SecurityManagerImpl; 16 17 import org.nextime.ion.framework.business.User; 18 import org.nextime.ion.framework.mapping.Mapping; 19 20 public class LoginAction extends Action { 21 22 public ActionForward perform( 23 ActionMapping mapping, 24 ActionForm form, 25 HttpServletRequest request, 26 HttpServletResponse response) 27 throws IOException , ServletException { 28 29 LoginForm lform = (LoginForm) form; 30 31 if (lform.getLogin() == null) 33 return (mapping.findForward("view")); 34 35 String login = lform.getLogin(); 36 String password = lform.getPassword(); 37 38 try { 40 Mapping.begin(); 41 User user = User.getInstance(login); 42 Mapping.rollback(); 43 if (!lform.getPassword().equals(user.getPassword())) { 44 ActionError error = new ActionError("error.login.badPassword"); 45 ActionErrors errors = new ActionErrors(); 46 errors.add("password", error); 47 request.setAttribute(ERROR_KEY, errors); 48 return (new ActionForward(mapping.getInput())); 49 } 50 Mapping.begin(); 51 boolean result = new SecurityManagerImpl().canLogIntoBackoffice(user); 52 Mapping.rollback(); 53 if ( !result ) { 54 ActionError error = new ActionError("error.login.notAuthorized"); 55 ActionErrors errors = new ActionErrors(); 56 errors.add("login", error); 57 request.setAttribute(ERROR_KEY, errors); 58 return (new ActionForward(mapping.getInput())); 59 } 60 request.getSession().setAttribute("userLogin",user.getLogin()); 61 } catch (Exception e) { 62 Mapping.rollback(); 63 ActionError error = new ActionError("error.login.badLogin"); 64 ActionErrors errors = new ActionErrors(); 65 errors.add("login", error); 66 request.setAttribute(ERROR_KEY, errors); 67 return (new ActionForward(mapping.getInput())); 68 } 69 70 request.setAttribute("reload","true"); 72 return (mapping.findForward("ok")); 73 74 } 75 76 } 77 | Popular Tags |