1 package ch.ige.edossier.web.server;
2
3 import java.sql.SQLException;
4 import java.util.Properties;
5 import org.apache.log4j.Logger;
6 import ch.ige.edossier.util.ServerProperties;
7 import ch.ige.edossier.web.server.dao.AccountDAO;
8 import ch.ige.edossier.web.vo.AccountVO;
9 import ch.ige.edossier.web.vo.MailSenderVO;
10
11
19 public class AccountAssembler
20 {
21 private static final Logger LOG = Logger.getLogger( AccountAssembler.class );
23
24
27 public AccountAssembler()
28 {}
29
30
36 public AccountVO checkPasswort( AccountVO accountVO ) throws Exception
37 {
38 AccountVO srvAccountVO = getAccountInfo( accountVO.getEmail() );
39
40 if( srvAccountVO != null )
41 {
42 if( srvAccountVO.getEmail().equals( accountVO.getEmail() ) )
44 {
45 if( srvAccountVO.getPwd().equals( accountVO.getPwd() ) )
46 {
47 srvAccountVO.setIsPwd( true );
48 }
49 return srvAccountVO;
50 }
51 }
52 return null;
53 }
54
55
62 public MailSenderVO sendPassword( String loginName, String languageCd ) throws Exception
63 {
64 AccountVO srvAccountVO = getAccountInfo( loginName );
65
66 if( srvAccountVO != null )
67 {
68 if( srvAccountVO != null )
69 {
70 return fillMailVO( srvAccountVO, languageCd );
71 }
72 }
73 return null;
74 }
75
76
83 private AccountVO getAccountInfo( String loginName ) throws Exception
84 {
85 try
86 {
87 AccountDAO accountDAO = new AccountDAO();
88 return accountDAO.select( loginName );
89 }
90 catch( SQLException sqlex )
91 {
92 LOG.error( "SQL-Fehler im AccountDAO.select(loginName): " + sqlex.getMessage() );
93 throw sqlex;
94 }
95 }
96
97
104 private MailSenderVO fillMailVO( AccountVO accountVO, String languageCd ) throws Exception
105 {
106 Properties properties = ServerProperties.loadWebProperties( languageCd );
107 MailSenderVO mailSenderVO = new MailSenderVO();
108 mailSenderVO.setAdressTo( accountVO.getEmail() );
109 mailSenderVO.setAdressFrom( "edossier-mailer@ipi.ch" );
110 mailSenderVO.setSubject( properties.getProperty( "mail.password.subject" ) );
111
112 StringBuffer buf = new StringBuffer();
113 buf.append( properties.getProperty( "mail.body.auto" ) ); buf.append( properties.getProperty( "mail.password.body.start" ) );
115 buf.append( accountVO.getEmail() );
116 buf.append( properties.getProperty( "mail.password.body.pwd" ) );
117 buf.append( accountVO.getPwd() );
118 buf.append( properties.getProperty( "mail.body.end" ) ); mailSenderVO.setBody( buf.toString() );
120
121 return mailSenderVO;
122 }
123 }
124