Changeset 414


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

login application
servlet data
ControllerEponge?

Location:
tapas/web
Files:
22 added
11 edited
1 copied

Legend:

Unmodified
Added
Removed
  • tapas/web/WEB-INF/servlet-context.xml

    r409 r414  
    3838        <property name="mappings"> 
    3939            <props> 
    40                 <prop key="/project">controller</prop> 
     40                <prop key="/data">controller</prop> 
     41                <prop key="/project">controllerEponge</prop> 
    4142                <prop key="/backoffice">controllerBackoffice</prop> 
    4243            </props> 
     
    6263 
    6364    <bean id="controller" class="com.ether.Controller" parent="controllerEther"/> 
     65 
    6466    <bean id="controllerBackoffice" class="com.ether.ControllerBackoffice" parent="controllerEther"> 
    6567        <property name="backofficeService" ref="backofficeService"/> 
    6668    </bean> 
     69 
     70    <bean id="controllerEponge" class="com.ether.ControllerEponge" parent="controllerEther"></bean> 
    6771</beans> 
  • tapas/web/WEB-INF/web.xml

    r382 r414  
    7171    </servlet-mapping> 
    7272 
     73    <servlet-mapping> 
     74        <servlet-name>eponge</servlet-name> 
     75        <url-pattern>/data</url-pattern> 
     76    </servlet-mapping> 
     77 
    7378    <session-config> 
    7479        <session-timeout>60</session-timeout> 
  • tapas/web/backoffice/user.jsp

    r409 r414  
    180180            interfaceTexts["bo.field.password"] = '<spring:message code="bo.field.password"/>'; 
    181181 
    182             interfaceTexts["<%=UserRole.ADMINISTRATOR%>"] = '<spring:message code="bo.user.administrator"/>'; 
    183             interfaceTexts["<%=UserRole.USER%>"] = '<spring:message code="bo.user.user"/>'; 
     182            interfaceTexts["<%=UserRole.ADMINISTRATOR%>"] = '<spring:message code="label.role.administrator"/>'; 
     183            interfaceTexts["<%=UserRole.USER%>"] = '<spring:message code="label.role.user"/>'; 
    184184 
    185185            interfaceTexts["<%=WebException.WebCode.USER_ALREADY_EXISTS%>"] = '<spring:message code="login.dataProtocol.alreadyExist"/>'; 
  • tapas/web/resources/templates/templateBackoffice.jsp

    r409 r414  
    110110    loginTexts["login.error.failed"] = "<spring:message code='login.error.failed'/>"; 
    111111    loginTexts["login.error.notAccepted"] = "<spring:message code='login.error.notAccepted'/>"; 
    112     loginTexts["<%=UserRole.ADMINISTRATOR%>"] = '<spring:message code="app.administrator"/>'; 
     112 
     113    loginTexts["<%=UserRole.ADMINISTRATOR%>"] = '<spring:message code="label.role.administrator"/>'; 
     114    loginTexts["<%=UserRole.USER%>"] = '<spring:message code="label.role.user"/>'; 
    113115 
    114116    var interfaceTemplate = new InterfaceTemplate(); 
  • tapas/web/resources/templates/templateBackoffice_script.jsp

    r413 r414  
    11<%@ page import="com.ether.WebHelper" %> 
     2 
    23<script type="text/javascript"> 
    34    var InterfaceTemplate = Class.create( { 
     
    1213 
    1314            /** *********** VARIABLES *********** **/ 
    14             this.path = "<%=request.getContextPath()%>"; 
    1515            this.webmaster = "rboipsl@ipsl.jussieu.fr"; 
    1616            this.jSONUser = <%=WebHelper.getJSONUser( request )%> ? <%=WebHelper.getJSONUser( request )%> : false; 
  • tapas/web/resources/templates/templateEther.jsp

    r409 r414  
     1<%@ page import="com.ether.user.UserRole" %> 
    12<%@ page contentType="text/html;charset=UTF-8" language="java" %> 
    23<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 
     
    1718    <ether:htmlCss cssFile="jquery-ui-1.8.16.custom/jquery-ui-1.8.16.custom"/> 
    1819    <ether:htmlCss cssFile="button"/> 
     20    <ether:htmlCss cssFile="complexButton"/> 
     21    <ether:htmlCss cssFile="TwitterLogin/front"/> 
    1922    <ether:htmlCss cssFile="mainEther"/> 
    2023    <ether:htmlCss cssFile="tapas"/> 
     
    2528    <ether:htmlJs jsFile="classesForJQuery/etherHelper"/> 
    2629    <ether:htmlJs jsFile="classesForJQuery/Button"/> 
     30    <ether:htmlJs jsFile="classesForJQuery/ComplexButton"/> 
     31    <ether:htmlJs jsFile="classesForJQuery/LoginButton"/> 
     32    <ether:htmlJs jsFile="TwitterLogin/javascripts/jquery.tipsy"/> 
    2733    <ether:htmlJs jsFile="apycom.com-5-red/menu"/> 
    2834 
     
    6167    <div id="menu" class="containerMenu"> 
    6268        <ul class="menu"> 
    63             <li><a href="project?methodName=viewForm" class="parent"><span>Formulaire</span></a> 
     69            <li><a href="data?methodName=viewForm" class="parent"><span>Formulaire</span></a> 
    6470 
    6571                <div> 
     
    130136    templateTexts["label.backoffice"] = '<spring:message code="label.backoffice"/>'; 
    131137 
     138    // Needed texts if you use the library LoginButton.js 
     139    var loginTexts = $A( "" ); 
     140    loginTexts["app.connexion"] = '<spring:message code="app.connexion"/>'; 
     141    loginTexts["login"] = '<spring:message code="login"/>'; 
     142    loginTexts["login.password"] = '<spring:message code="login.password"/>'; 
     143    loginTexts["login.sign"] = '<spring:message code="login.sign"/>'; 
     144    loginTexts["login.pwdForget"] = '<spring:message code="login.pwdForget"/>'; 
     145    loginTexts["login.loginForget"] = '<spring:message code="login.loginForget"/>'; 
     146    loginTexts["login.loginForget.help"] = '<spring:message code="login.loginForget.help"/>'; 
     147    loginTexts["login.inscription"] = '<spring:message code="login.inscription"/>'; 
     148    loginTexts["login.error.notFound"] = "<spring:message code='login.error.notFound'/>"; 
     149    loginTexts["login.error.wrongPassword"] = "<spring:message code='login.error.wrongPassword'/>"; 
     150    loginTexts["login.error.failed"] = "<spring:message code='login.error.failed'/>"; 
     151    loginTexts["login.error.notAccepted"] = "<spring:message code='login.error.notAccepted'/>"; 
     152    loginTexts["login.text"] = "<spring:message code='login.text'/>"; 
     153 
     154    loginTexts["<%=UserRole.ADMINISTRATOR%>"] = '<spring:message code="label.role.administrator"/>'; 
     155    loginTexts["<%=UserRole.USER%>"] = '<spring:message code="label.role.user"/>'; 
     156 
    132157    var interfaceTemplate = new InterfaceTemplate(); 
    133158</script> 
  • tapas/web/resources/templates/templateEther_script.jsp

    r409 r414  
     1<%@ page import="com.ether.WebHelper" %> 
     2 
    13<script type="text/javascript"> 
    24    var InterfaceTemplate = Class.create( { 
     
    1214            // TODO : vérifier cette adresse de webmaster !!!! 
    1315            this.webmaster = "rboipsl@ipsl.jussieu.fr"; 
     16            this.jSONUser = <%=WebHelper.getJSONUser( request )%> ? <%=WebHelper.getJSONUser( request )%> : false; 
    1417 
    1518            /** ************ CREATE ************ **/ 
     19            this.createLogin(); 
    1620            this.createTools(); 
    1721        }, 
     
    2529            var languageButton = new Button( {value:templateTexts["label.language.to.switch"], parent:this.containerTools, id:"button_language", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickLanguage, this )} ); 
    2630            var homeButton = new Button( {value:templateTexts["label.home"], parent:this.containerTools, id:"button_home", className: "red_button", classNameText:"red_button_text", onClick:this.onClickHome} ); 
     31        }, 
     32 
     33        createLogin: function() 
     34        { 
     35            var loginModule = new LoginButton( {parent:this.containerLogin, urlLogin:"project?methodName=login", urlLogout:"project?methodName=logout", webmaster: this.webmaster, isNeededInscription:true, anotherOnClickLogin:this.updateLoginOrLogout, anotherOnClickLogout:this.updateLoginOrLogout } ); 
     36            loginModule.setJSONUser( this.jSONUser ); 
     37            loginModule.display(); 
     38//            setLoginModule( this.loginModule ); 
    2739        }, 
    2840 
  • tapas/web/src/com/ether/Controller.java

    r411 r414  
    99import org.apache.commons.logging.Log; 
    1010import org.apache.commons.logging.LogFactory; 
    11 import org.jetbrains.annotations.NotNull; 
    12 import org.springframework.beans.factory.annotation.Required; 
    1311 
    1412import java.util.HashMap; 
     
    2624    /** *********************** VIEWS ***************************** **/ 
    2725    /** *********************************************************** **/ 
    28     @ControllerMethod(view = VIEW_INIT)public Map<String, Object> home() 
     26    @ControllerMethod(view = VIEW_FORM_TAPAS) 
     27    public Map<String, Object> viewForm() 
    2928            throws WebException 
    3029    { 
    31         return new HashMap<String, Object>(); 
    32     } 
    33  
    34     @ControllerMethod(view = VIEW_FORM_TAPAS) 
    35     public Map<String, Object> viewForm() 
    36             throws WebException{ 
    3730        return new HashMap<String, Object>(); 
    3831    } 
     
    5851    private static final Log LOGGER = LogFactory.getLog( Controller.class ); 
    5952 
    60     private static final String VIEW_INIT = "init"; 
    6153    private static final String VIEW_FORM_TAPAS = "project/formTapas"; 
    6254} 
  • 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"; 
  • tapas/web/src/com/ether/ControllerEther.java

    r412 r414  
    4747            throws WebException 
    4848    { 
    49     } 
    50  
    51     /** 
    52      * This method logs a user 
    53      * 
    54      * @param login 
    55      * @param password 
    56      * @param request 
    57      * @return 
    58      * @throws ServiceException 
    59      */ 
    60     @ControllerMethod(requestMandatory = true, jsonResult = true) 
    61     public JSONObject login( @ParamName(ParameterConstants.PARAMETER_LOGIN) final String login, 
    62                              @ParamName(ParameterConstants.PARAMETER_PWD) final String password, 
    63                              @NotNull final HttpServletRequest request ) 
    64             throws ServiceException 
    65     { 
    66         final JSONObject jSONUser = new JSONObject(); 
    67         final JSONObject result = new JSONObject(); 
    68  
    69         if( login != null && password != null ) 
    70         { 
    71             try 
    72             { 
    73                 final User user = _tapasService.getUserByEmail( login ); 
    74                 final String encryptedPassword = EtherHelper.encryptPassword( password ); 
    75                 if( user == null ) 
    76                     result.put( "errors", "login.error.notFound" ); 
    77                 else if( !encryptedPassword.equals( user.getPassword() ) ) 
    78                     result.put( "errors", "login.error.wrongPassword" ); 
    79                 else 
    80                 { 
    81                     request.getSession().setAttribute( "SES_USER", user ); 
    82                     jSONUser.put( "name", user.getLastName() ); 
    83                     jSONUser.put( "firstName", user.getFirstName() ); 
    84                     jSONUser.put( "role", user.getRole().name() ); 
    85                 } 
    86             } 
    87             catch( Exception e ) 
    88             { 
    89                 result.put( "errors", "login.error.failed" ); 
    90             } 
    91         } 
    92  
    93         if( !jSONUser.isEmpty() ) 
    94             result.put( "jSONUser", jSONUser ); 
    95         return result; 
    96     } 
    97  
    98     @ControllerMethod(requestMandatory = true, jsonResult = true) 
    99     public JSONObject logout( @NotNull final HttpServletRequest request ) 
    100             throws ServiceException 
    101     { 
    102         request.getSession().setAttribute( "SES_USER", null ); 
    103         request.getSession().invalidate(); 
    104  
    105         return new JSONObject(); 
    10649    } 
    10750 
  • tapas/web/src/messages_en.properties

    r409 r414  
    1717label.mail=Email 
    1818label.backoffice=Backoffice 
     19 
     20label.role.administrator=Administrateur 
     21label.role.user=Utilisateur 
    1922 
    2023error.ERROR_JSON_TAPAS_IS_NULL=Error to create the form 
     
    9396bo.user.remove.confirm=Do you really want to remove the user 
    9497 
    95 bo.user.accepted=Accepted 
    96 bo.user.refused=Refused 
    97 bo.user.waiting=Waiting 
    98 bo.user.administrator=Administrator 
    99 bo.user.user=User 
    100  
    10198bo.field.lastName=The field lastName must be filled 
    10299bo.field.email=The field email must be filled 
  • tapas/web/src/messages_fr.properties

    r409 r414  
    1717label.mail=Email 
    1818label.backoffice=Backoffice 
     19 
     20label.role.administrator=Administrator 
     21label.role.user=User 
    1922 
    2023error.ERROR_JSON_TAPAS_IS_NULL=Erreur de création du formulaire Tapas 
     
    9295bo.user.remove.confirm=Do you really want to remove the user 
    9396 
    94 bo.user.accepted=Accepted 
    95 bo.user.refused=Refused 
    96 bo.user.waiting=Waiting 
    97 bo.user.administrator=Administrator 
    98 bo.user.user=User 
    99  
    10097bo.field.lastName=The field lastName must be filled 
    10198bo.field.email=The field email must be filled 
Note: See TracChangeset for help on using the changeset viewer.