Ignore:
Timestamp:
03/15/12 12:53:14 (12 years ago)
Author:
vmipsl
Message:

login application
servlet data
ControllerEponge?

File:
1 copied

Legend:

Unmodified
Added
Removed
  • tapas/web/src/com/ether/ControllerEponge.java

    r366 r414  
    55import com.ether.user.User; 
    66import com.ether.user.UserRole; 
    7 import com.ether.user.UserState; 
    8 import com.medias.Constantes; 
    9 import com.medias.Context; 
    10 import com.medias.annuaire.Personne; 
    11 import com.medias.mail.Mail; 
    12 import com.medias.mail.MailFactory; 
    137import net.sf.json.JSONObject; 
    148import org.apache.commons.logging.Log; 
     
    1711import org.jetbrains.annotations.Nullable; 
    1812 
    19 import javax.mail.MessagingException; 
    2013import javax.servlet.http.HttpServletRequest; 
    2114import java.security.DigestException; 
    2215import java.security.NoSuchAlgorithmException; 
    23 import java.util.ArrayList; 
    2416import java.util.Date; 
    2517import java.util.HashMap; 
     
    2820/** 
    2921 * @author vmipsl 
    30  * @date 12 nov 2011 
     22 * @date 15 march 2012 
    3123 */ 
    3224public class ControllerEponge 
     
    3628    /** *********************** VIEWS ***************************** **/ 
    3729    /** *********************************************************** **/ 
    38     @ControllerMethod(view = VIEW_ERRORS) 
    39     public Map<String, Object> viewErrors() 
    40             throws ServiceException 
     30    @ControllerMethod(view = VIEW_INIT) 
     31    public Map<String, Object> home() 
     32            throws WebException 
    4133    { 
    4234        return new HashMap<String, Object>(); 
    4335    } 
    4436 
    45     @ControllerMethod(view = VIEW_LOGIN) 
    46     public Map<String, Object> viewLogin() 
     37    @ControllerMethod(view = VIEW_ERRORS) 
     38    public Map<String, Object> viewErrors() 
    4739            throws ServiceException 
    4840    { 
     
    5648        final MethodDescription methodDescription = getMethods().get( "viewHomeDataProtocol" ); 
    5749 
    58         if( Context.getLangue( request ).equals( Constantes.french_language ) ) 
    59             methodDescription.setView( VIEW_DATA_PROTOCOL_FR ); 
    60         else 
    61             methodDescription.setView( VIEW_DATA_PROTOCOL_EN ); 
     50//        if( Context.getLangue( request ).equals( Constantes.french_language ) ) 
     51//            methodDescription.setView( VIEW_DATA_PROTOCOL_FR ); 
     52//        else 
     53//            methodDescription.setView( VIEW_DATA_PROTOCOL_EN ); 
    6254        return new HashMap<String, Object>(); 
    6355    } 
     
    6658    /** *********************** CALLS ***************************** **/ 
    6759    /** *********************************************************** **/ 
     60    /** 
     61     * This method logs a user 
     62     * 
     63     * @param login 
     64     * @param password 
     65     * @param request 
     66     * @return 
     67     * @throws ServiceException 
     68     */ 
    6869    @ControllerMethod(requestMandatory = true, jsonResult = true) 
    6970    public JSONObject login( @ParamName(ParameterConstants.PARAMETER_LOGIN) final String login, 
     
    7273            throws ServiceException 
    7374    { 
    74         final JSONObject jSONPeople = new JSONObject(); 
     75        final JSONObject jSONUser = new JSONObject(); 
    7576        final JSONObject result = new JSONObject(); 
    7677 
     
    7980            try 
    8081            { 
    81                 final User user = getEtherService().getUserByEmail( login ); 
     82                final User user = getTapasService().getUserByEmail( login ); 
    8283                final String encryptedPassword = EtherHelper.encryptPassword( password ); 
    8384                if( user == null ) 
     
    8586                else if( !encryptedPassword.equals( user.getPassword() ) ) 
    8687                    result.put( "errors", "login.error.wrongPassword" ); 
    87                 else if( !UserState.ACCEPTED.equals( user.getState() ) ) 
    88                     result.put( "errors", "login.error.notAccepted" ); 
    8988                else 
    9089                { 
    91                     Personne person = getEtherService().getPeopleByEmail( user.getEmail() ); 
    92                     if( person == null ) 
    93                     { 
    94                         // This is a simple user with no set of data _ Personne in session is used for tests in .jsp 
    95                         person = new Personne(); 
    96                         person.setNom( user.getLastName() ); 
    97                         person.setPrenom( user.getFirstName() ); 
    98                         person.setMail( user.getEmail() ); 
    99                         person.setRoles( user.getRole().name() ); 
    100                         // Can't be null because of the tests in .jsp (upload.jsp by example) 
    101                         person.setJeux( new ArrayList<String>() ); 
    102                     } 
    103  
    104                     request.getSession().setAttribute( "SES_USER", person ); 
    105                     jSONPeople.put( "name", user.getLastName() ); 
    106                     jSONPeople.put( "firstName", user.getFirstName() ); 
    107                     jSONPeople.put( "role", user.getRole().name() ); 
     90                    request.getSession().setAttribute( "SES_USER", user ); 
     91                    jSONUser.put( "name", user.getLastName() ); 
     92                    jSONUser.put( "firstName", user.getFirstName() ); 
     93                    jSONUser.put( "role", user.getRole().name() ); 
    10894                } 
    10995            } 
     
    114100        } 
    115101 
    116         if( !jSONPeople.isEmpty() ) 
    117             result.put( "jSONPeople", jSONPeople ); 
     102        if( !jSONUser.isEmpty() ) 
     103            result.put( "jSONUser", jSONUser ); 
    118104        return result; 
    119105    } 
     
    129115    } 
    130116 
     117 
    131118    @ControllerMethod(jsonResult = true) 
    132119    public JSONObject createAccount( @NotNull @ParamName(ParameterConstants.PARAMETER_NAME) final String lastName, 
     
    138125        try 
    139126        { 
    140             final User existingUser = getEtherService().getUserByEmail( email ); 
     127            final User existingUser = getTapasService().getUserByEmail( email ); 
    141128            if( null == existingUser ) 
    142129            { 
     
    144131 
    145132                final String encryptedPassword = EtherHelper.encryptPassword( password ); 
    146                 final User user = new User( lastName, firstName, email, encryptedPassword, UserRole.COORDINATOR, UserState.WAITING, false, creationDate ); 
     133                final User user = new User( lastName, firstName, email, encryptedPassword, UserRole.USER, false, creationDate ); 
    147134 
    148                 getEtherService().createUser( user ); 
     135                getTapasService().createUser( user ); 
    149136 
    150137                // Send email to administrator to inform there is a new account 
     
    175162            throws WebException 
    176163    { 
    177         try 
    178         { 
    179             final MailFactory mailFactory = (MailFactory) getServletContext().getAttribute( "APP_MAILFACTORY" ); 
    180             final String from = (String) getServletContext().getAttribute( "APP_WEBMASTER" ); 
    181             final String toPI = (String) getServletContext().getAttribute( "APP_PI" ); 
    182             final String subject = "[MEGAPOLI] Nouvelle demande de compte utilisateur"; 
    183             final String content = "Hello Matthias,\n\nUne nouvelle demande de compte vient d'arriver.\n\n" + 
    184                     "   - Nom : " + user.getLastName() + '\n' + 
    185                     "   - Prénom : " + user.getFirstName() + '\n' + 
    186                     "   - Email : " + user.getEmail() + "\n\n" + 
    187                     "Tu peux accepter ou refuser son inscription via le BO : http://ether.ipsl.jussieu.fr/megapoli/backoffice\n\n" + 
    188                     "Bonne soirée,\nLe serveur masqué"; 
    189  
    190             final Mail mailAdministrator = new Mail( from, from, null, content, subject ); 
    191             mailFactory.sendMail( mailAdministrator ); 
    192             final Mail mailPI = new Mail( from, toPI, null, content, subject ); 
    193             mailFactory.sendMail( mailPI ); 
    194         } 
    195         catch( MessagingException e ) 
    196         { 
    197             throw new WebException( WebException.WebCode.ERROR_EMAIL_CANNOT_BE_SEND, "The email cannot be send to the megapoli administrator" ); 
    198         } 
     164//        try 
     165//        { 
     166//            final MailFactory mailFactory = (MailFactory) getServletContext().getAttribute( "APP_MAILFACTORY" ); 
     167//            final String from = (String) getServletContext().getAttribute( "APP_WEBMASTER" ); 
     168//            final String toPI = (String) getServletContext().getAttribute( "APP_PI" ); 
     169//            final String subject = "[MEGAPOLI] Nouvelle demande de compte utilisateur"; 
     170//            final String content = "Hello Matthias,\n\nUne nouvelle demande de compte vient d'arriver.\n\n" + 
     171//                    "   - Nom : " + user.getLastName() + '\n' + 
     172//                    "   - Prénom : " + user.getFirstName() + '\n' + 
     173//                    "   - Email : " + user.getEmail() + "\n\n" + 
     174//                    "Tu peux accepter ou refuser son inscription via le BO : http://ether.ipsl.jussieu.fr/megapoli/backoffice\n\n" + 
     175//                    "Bonne soirée,\nLe serveur masqué"; 
     176// 
     177//            final Mail mailAdministrator = new Mail( from, from, null, content, subject ); 
     178//            mailFactory.sendMail( mailAdministrator ); 
     179//            final Mail mailPI = new Mail( from, toPI, null, content, subject ); 
     180//            mailFactory.sendMail( mailPI ); 
     181//        } 
     182//        catch( MessagingException e ) 
     183//        { 
     184//            throw new WebException( WebException.WebCode.ERROR_EMAIL_CANNOT_BE_SEND, "The email cannot be send to the megapoli administrator" ); 
     185//        } 
    199186    } 
    200187 
    201188    private static final Log LOGGER = LogFactory.getLog( ControllerEponge.class ); 
    202189 
     190    private static final String VIEW_INIT = "init"; 
    203191    private static final String VIEW_ERRORS = "project/errors"; 
    204     private static final String VIEW_LOGIN = "project/login"; 
    205192    private static final String VIEW_DATA_PROTOCOL_EN = "project/home_dataProtocol_en"; 
    206193    private static final String VIEW_DATA_PROTOCOL_FR = "project/home_dataProtocol_fr"; 
Note: See TracChangeset for help on using the changeset viewer.