1 4 package xpetstore.web.webwork.action.signon; 5 6 import javax.servlet.http.HttpServletResponse ; 7 8 import cirrus.hibernate.ObjectNotFoundException; 9 import cirrus.hibernate.Session; 10 11 import webwork.action.ServletResponseAware; 12 13 import xpetstore.domain.Customer; 14 15 import xpetstore.web.webwork.action.BaseAction; 16 17 18 26 public class LoginAction 27 extends BaseAction 28 implements ServletResponseAware 29 { 30 32 private String _password; 33 private HttpServletResponse _response; 34 private String _userId; 35 36 38 41 protected String doExecute( ) 42 throws Exception 43 { 44 Session s = getHibernateSession( ); 45 46 try 47 { 48 Customer c = ( Customer ) s.load( Customer.class, _userId ); 49 50 if ( c.getAccount( ).matchPassword( _password ) ) 51 { 52 initSession( c ); 53 54 55 if ( ( _redirectUri != null ) && ( _redirectUri.length( ) > 0 ) ) 56 { 57 _response.sendRedirect( _redirectUri ); 58 return NONE; 59 } 60 61 62 return SUCCESS; 63 } 64 else 65 { 66 addError( "login", getText( "authentication_failed" ) ); 67 return ERROR; 68 } 69 } 70 catch ( ObjectNotFoundException o ) 71 { 72 addError( "login", getText( "authentication_failed" ) ); 73 74 return ERROR; 75 } 76 finally 77 { 78 s.close( ); 79 } 80 } 81 82 85 public String getPassword( ) 86 { 87 return _password; 88 } 89 90 93 public String getUserId( ) 94 { 95 return _userId; 96 } 97 98 102 public void setPassword( String password ) 103 { 104 _password = password; 105 } 106 107 110 public void setServletResponse( HttpServletResponse response ) 111 { 112 _response = response; 113 } 114 115 119 public void setUserId( String login ) 120 { 121 _userId = login; 122 } 123 } 124 | Popular Tags |