Changeset 422


Ignore:
Timestamp:
03/19/12 18:39:02 (12 years ago)
Author:
vmipsl
Message:

Envoi mail
Correctif annontation Id
properties

Location:
tapas
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • tapas/common/implementation/com/ether/EtherHelper.java

    r417 r422  
    44import org.jetbrains.annotations.NotNull; 
    55import org.jetbrains.annotations.Nullable; 
    6  
     6import org.springframework.mail.javamail.JavaMailSenderImpl; 
     7import org.springframework.mail.javamail.MimeMessageHelper; 
     8 
     9import javax.mail.MessagingException; 
     10import javax.mail.internet.MimeMessage; 
    711import java.io.BufferedWriter; 
    812import java.io.FileWriter; 
     
    216220        } 
    217221    } 
     222 
     223    /** 
     224     * This method sends a message 
     225     * host (see in properties) : mailhost.ipsl.jussieu.fr 
     226     * 
     227     * @param host 
     228     * @param to 
     229     * @param from 
     230     * @param subject 
     231     * @param text 
     232     * @throws FormattedException 
     233     */ 
     234    public static void sendMessage( @NotNull final String host, @NotNull final String from, @NotNull final String to, @NotNull final String subject, @NotNull final String text ) 
     235            throws FormattedException 
     236    { 
     237        try 
     238        { 
     239            final JavaMailSenderImpl sender = new JavaMailSenderImpl(); 
     240            sender.setHost( host ); 
     241 
     242            final MimeMessage message = sender.createMimeMessage(); 
     243            final MimeMessageHelper helper = new MimeMessageHelper( message ); 
     244            helper.setFrom( from ); 
     245            helper.setTo( to ); 
     246            helper.setSubject( subject ); 
     247            helper.setText( text ); 
     248            sender.send( message ); 
     249        } 
     250        catch( MessagingException e ) 
     251        { 
     252            throw new FormattedException( FormattedException.FormattedCode.ERROR_TO_SEND_MESSAGE, e ); 
     253        } 
     254    } 
    218255} 
  • tapas/common/interface/com/ether/FormattedException.java

    r417 r422  
    9090    { 
    9191        ERROR_IO_TO_EXECUTE_PROCESS, 
     92        ERROR_TO_SEND_MESSAGE, 
    9293    } 
    9394 
  • tapas/domain/interface/com/ether/tapas/Observatory.java

    r421 r422  
    99public class Observatory 
    1010{ 
    11     @NotNull 
    1211    public Integer getId() 
    1312    { 
     
    1514    } 
    1615 
    17     public void setId( @NotNull final Integer id ) 
     16    public void setId( final Integer id ) 
    1817    { 
    1918        _id = id; 
     
    6463    } 
    6564 
    66     @NotNull 
    6765    private Integer _id; 
    6866    @NotNull 
  • tapas/web/src/com/ether/ControllerEponge.java

    r416 r422  
    1010import org.jetbrains.annotations.NotNull; 
    1111import org.jetbrains.annotations.Nullable; 
    12  
     12import org.springframework.mail.javamail.JavaMailSenderImpl; 
     13import org.springframework.mail.javamail.MimeMessageHelper; 
     14 
     15import javax.mail.MessagingException; 
     16import javax.mail.internet.MimeMessage; 
    1317import javax.servlet.http.HttpServletRequest; 
    1418import java.security.DigestException; 
     
    124128 
    125129                // Send email to administrator to inform there is a new account 
    126                 sendEmailToAdministrator( user ); 
     130                sendEmailToAdministratorAndUser( user ); 
    127131            } 
    128132            else 
     
    142146 
    143147    /** 
    144      * This method create and send an email to the administrator to inform there is a new account to validate 
     148     * This method create and send an email to : 
     149     * - the administrator to inform there is a new created account 
     150     * - the user to inform his account is created 
    145151     * 
    146152     * @param user 
    147153     * @throws WebException 
    148154     */ 
    149     private void sendEmailToAdministrator( @NotNull final User user ) 
     155    private void sendEmailToAdministratorAndUser( @NotNull final User user ) 
    150156            throws WebException 
    151157    { 
    152 //        try 
    153 //        { 
    154 //            final MailFactory mailFactory = (MailFactory) getServletContext().getAttribute( "APP_MAILFACTORY" ); 
    155 //            final String from = (String) getServletContext().getAttribute( "APP_WEBMASTER" ); 
    156 //            final String toPI = (String) getServletContext().getAttribute( "APP_PI" ); 
    157 //            final String subject = "[MEGAPOLI] Nouvelle demande de compte utilisateur"; 
    158 //            final String content = "Hello Matthias,\n\nUne nouvelle demande de compte vient d'arriver.\n\n" + 
    159 //                    "   - Nom : " + user.getLastName() + '\n' + 
    160 //                    "   - Prénom : " + user.getFirstName() + '\n' + 
    161 //                    "   - Email : " + user.getEmail() + "\n\n" + 
    162 //                    "Tu peux accepter ou refuser son inscription via le BO : http://ether.ipsl.jussieu.fr/megapoli/backoffice\n\n" + 
    163 //                    "Bonne soirée,\nLe serveur masqué"; 
    164 // 
    165 //            final Mail mailAdministrator = new Mail( from, from, null, content, subject ); 
    166 //            mailFactory.sendMail( mailAdministrator ); 
    167 //            final Mail mailPI = new Mail( from, toPI, null, content, subject ); 
    168 //            mailFactory.sendMail( mailPI ); 
    169 //        } 
    170 //        catch( MessagingException e ) 
    171 //        { 
    172 //            throw new WebException( WebException.WebCode.ERROR_EMAIL_CANNOT_BE_SEND, "The email cannot be send to the megapoli administrator" ); 
    173 //        } 
     158        try 
     159        { 
     160            final String host = getProperty( "mail.host" ); 
     161            final String webMaster = getProperty( "mail.webmaster" ); 
     162            final JavaMailSenderImpl sender = new JavaMailSenderImpl(); 
     163            sender.setHost( host ); 
     164 
     165            final MimeMessage message = sender.createMimeMessage(); 
     166            final MimeMessageHelper helper = new MimeMessageHelper( message ); 
     167 
     168            // Mail Admin 
     169            final String subjectAdmin = "[TAPAS] Nouveau compte utilisateur"; 
     170            final String contentAdmin = "Nouvelle création de compte : \n\n" + 
     171                    "   - Nom : " + user.getLastName() + '\n' + 
     172                    "   - Prénom : " + user.getFirstName() + '\n' + 
     173                    "   - Email : " + user.getEmail() + "\n\n" + 
     174                    "Le serveur de mail masqué"; 
     175 
     176            helper.setFrom( webMaster ); 
     177            helper.setTo( webMaster ); 
     178            helper.setSubject( subjectAdmin ); 
     179            helper.setText( contentAdmin ); 
     180            sender.send( message ); 
     181 
     182            // Mail User 
     183            final String subjectUser = "[TAPAS] New account"; 
     184            final String contentUser = "Dear " + user.getLastName() + "\n\n" + 
     185                    "Your account on TAPAS is now created. You can access to the website with your email as login and your password.\n\n" + 
     186                    "The TAPAS Administrator"; 
     187 
     188            helper.setFrom( webMaster ); 
     189            helper.setTo( user.getEmail() ); 
     190            helper.setSubject( subjectUser ); 
     191            helper.setText( contentUser ); 
     192            sender.send( message ); 
     193        } 
     194        catch( MessagingException e ) 
     195        { 
     196            throw new WebException( WebException.WebCode.ERROR_EMAIL_CANNOT_BE_SEND, "The email cannot be send to the TAPAS administrator or USER" ); 
     197        } 
    174198    } 
    175199 
  • tapas/web/src/com/ether/ControllerEther.java

    r416 r422  
    3939import java.util.List; 
    4040import java.util.Map; 
     41import java.util.Properties; 
    4142 
    4243public class ControllerEther 
     
    5253            throws WebException 
    5354    { 
     55    } 
     56 
     57    /** 
     58     * @return 
     59     * @throws WebException 
     60     */ 
     61    public String getProperty( @NotNull final String property ) 
     62            throws WebException 
     63    { 
     64        try 
     65        { 
     66            final String webInfPath = getServletContext().getRealPath( "WEB-INF" ); 
     67            final Properties prop = new Properties(); 
     68            prop.load( new FileInputStream( webInfPath + "/classes/tapas.properties" ) ); 
     69            return prop.getProperty( property ); 
     70        } 
     71        catch( IOException e ) 
     72        { 
     73            throw new WebException( WebException.WebCode.ERROR_TO_READ_FILE_PROPERTIES, e ); 
     74        } 
    5475    } 
    5576 
  • tapas/web/src/com/ether/WebException.java

    r419 r422  
    4545        ERROR_ENCRYPT_PASSWORD, 
    4646        ERROR_EMAIL_CANNOT_BE_SEND, 
    47         ERROR_NO_OBSERVATORY_FOUND 
     47              ERROR_NO_OBSERVATORY_FOUND, 
     48        ERROR_TO_READ_FILE_PROPERTIES 
    4849    } 
    4950 
  • tapas/web/src/tapas.properties

    r416 r422  
    1 inWork=Work in progress.. 
    2 language=en 
    3 label.language.to.switch=French 
    4 label.language.value.to.switch=fr 
    5  
    6 app.title=Tapas 
    7 app.fulltitle=Full title de Tapas 
    8 app.connexion=Connection 
    9 app.administrator=Administrator 
    10 app.yes=Yes 
    11 app.no=No 
    12  
    13 title.home=Tapas data 
    14  
    15 label.home=Home 
    16 label.map=Map 
    17 label.mail=Email 
    18 label.backoffice=Backoffice 
    19  
    20 label.role.administrator=Administrateur 
    21 label.role.user=Utilisateur 
    22  
    23 error.ERROR_JSON_TAPAS_IS_NULL=Error to create the form 
    24  
    25 label.submitButton=RUN 
    26  
    27 ################################################################ 
    28 ####################### ERRORS ################################# 
    29 ################################################################ 
    30 USER_ALREADY_EXISTS=This email is already used, you have to give another one 
    31  
    32  
    33 ################################################################ 
    34 ####################### LOGIN ################################## 
    35 ################################################################ 
    36 login.authentification=Authentification 
    37 login.intro=Please login to access the protected areas of this website. 
    38 login=Login 
    39 login.password=Password 
    40 login.sign=Sign in 
    41 login.loginForget=Forgot your username ? 
    42 login.loginForget.help=If you remember your password, try logging in with your email 
    43 login.pwdForget=Forgot your password ? 
    44 login.inscription=New inscription 
    45 login.text=Please login to access the protected areas of this website. 
    46  
    47 login.dataProtocolAccept=You have to accept the data protocol to ask for an account 
    48 login.dataProtocolFields=Fields 'LastName', 'Email' and 'Password' must be filled 
    49 login.dataProtocol.account=Your account is now activated. You can login with your email and password. 
    50  
    51 login.error.notAccepted=You are not allowed to access to protected areas. 
    52 login.error.bo.notAccepted=You are not authorized to access to backoffice. 
    53 login.error.notFound=Unknown login.<br> To register and access the protected areas of this site, please click on 'New inscription'.<br> 
    54 login.error.wrongPassword=Wrong password. 
    55 login.error.failed=The logon transaction failed. Please contact the <a href\='mailto\:{0}?subject\=[TAPAS]'>webmaster</a> to report this problem.<br> 
    56 login.error.unknown=You are not authentified or you lost your session, please register. 
    57  
    58  
    59  
    60 ################################################################ 
    61 ##################### BACKOFFICE ############################### 
    62 ################################################################ 
    63 bo.fulltitle=TAPAS Backoffice 
    64 bo.site=Tapas 
    65 bo.id=Id 
    66 bo.action=Action 
    67 bo.actions=Actions 
    68 bo.modify=Modify 
    69 bo.remove=Remove 
    70 bo.add=Add 
    71 bo.accept=Accept 
    72 bo.refuse=Refuse 
    73 bo.init=Init 
    74 bo.go=Go 
    75 bo.all=All 
    76 bo.total.number=Total number 
    77 bo.previous=Previous 
    78 bo.next=Next 
    79 bo.sortBy=Sort by 
    80 bo.viewBy=View by 
    81 bo.sort.asc=Sort asc by 
    82 bo.user=Users 
    83 bo.user.waitinglist=List of users waiting to have an access to data 
    84 bo.user.waitinglist.help=(an email will be sent to the user with your choice (accept or refuse)) 
    85 bo.user.list=List of users 
    86 bo.noUser=No user 
    87 bo.user.lastName=Lastname 
    88 bo.user.firstName=Firstname 
    89 bo.user.email=Email 
    90 bo.user.password=Password 
    91 bo.user.password.same=Keep same password 
    92 bo.user.password.same.help=(only to modify a password) 
    93 bo.user.role=Role 
    94 bo.user.laboratory=Laboratory 
    95 bo.user.country=Country 
    96 bo.user.creationDate=Creation date 
    97 bo.user.state=State 
    98 bo.user.state.help=Inscription state (can be removed, unactif, refused, ...) 
    99 bo.user.boAccess=BO 
    100 bo.user.boAccess.help=Access to the backoffice 
    101 bo.user.add=Add a new user 
    102 bo.user.modify=Modify the user 
    103 bo.user.remove.confirm=Do you really want to remove the user 
    104  
    105 bo.field.lastName=The field lastName must be filled 
    106 bo.field.email=The field email must be filled 
    107 bo.field.password=The field password must be filled 
    108  
    109 bo.user.emailNotSend=The email to the user cannot be sent, the email seems not valid : 
     1mail.host=mailhost.ipsl.jussieu.fr 
     2mail.webmaster=rboipsl@ipsl.jussieu.fr 
Note: See TracChangeset for help on using the changeset viewer.