1 package ch.ige.edossier.web.struts;
2
3 import javax.servlet.http.HttpServletRequest;
4 import javax.servlet.http.HttpServletResponse;
5 import javax.servlet.http.HttpSession;
6 import org.apache.log4j.Logger;
7 import org.apache.struts.action.*;
8 import ch.ige.edossier.web.server.EDossierControl;
9 import ch.ige.edossier.web.vo.AccountVO;
10 import ch.ige.edossier.web.vo.DossierOverviewVO;
11
12
24 public class LoginAction extends Action
25 {
26 private static final Logger LOG = Logger.getLogger( LoginAction.class );
28
29
39 public ActionForward execute( ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse )
40 {
41 ActionErrors errors = new ActionErrors();
42 HttpSession session = httpServletRequest.getSession();
43 LoginForm loginForm = ( LoginForm )actionForm;
44
45 EDossierFacade eFacade = new EDossierControl();
46 AccountVO accountVO = new AccountVO();
47
48 try
49 {
50 accountVO.setEmail( loginForm.getTxfEmail() );
51 accountVO.setPwd( loginForm.getTxfPW() );
52 accountVO = eFacade.checkPassword( accountVO );
53
54 if( accountVO != null )
55 {
56 if( accountVO.getIsPwd() )
57 {
58 session.setAttribute( "accountVO", accountVO );
59 DossierOverviewVO dossierOverviewVO = eFacade.getDossiers( accountVO.getAccountId() );
60 session.setAttribute( "dossierOverviewVO", dossierOverviewVO );
61
62 session.setAttribute( "token", new Boolean( true ) );
64 loginForm.reset( actionMapping, httpServletRequest );
65 return( actionMapping.findForward( "forward" ) );
66 }
67 else
68 {
69 errors.add( "accountVO", new ActionError( "error.login.pwd" ) );
70 saveErrors( httpServletRequest, errors );
71 return( actionMapping.findForward( "self" ) );
72 }
73 }
74 else
75 {
76 errors.add( "accountVO", new ActionError( "error.login.account" ) );
77 saveErrors( httpServletRequest, errors );
78 return( actionMapping.findForward( "self" ) );
79 }
80 }
81 catch( Exception ex )
82 {
83 LOG.error( "Error: " + ex.getMessage() );
84 errors.add( "accountVO", new ActionError( "error.login.account", ex.getMessage() ) );
85 saveErrors( httpServletRequest, errors );
86 return( new ActionForward( actionMapping.getInput() ) );
87 }
88 }
89 }
90