Antonio,

I dislike actions... but, on occasions, they're useful:

/*
 *
 * @(#)IsUserLoggedAction.java
 * @version 0.1.0 08/07/02
 *
 * Descrizione:
 * Controlla che l'utente sia loggato, restituisce una mappa vuota
 * se lo è, e null se non è loggato.
 *
 * Storia:
 * @author <a href="mailto:[EMAIL PROTECTED]";>Luca Morandini</a>
 * 08/07/02 Creazione
 *
 */

package com.lucamorandini.cocoon;

import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.Constants;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.acting.AbstractAction;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;


public class IsUserLoggedAction extends AbstractAction
        implements ThreadSafe {

        public Map act( Redirector redirector, SourceResolver resolver,
                Map objectModel, String source, Parameters param )
                throws Exception {

                try {
                        Request req= ObjectModelHelper.getRequest(objectModel);
                if (req == null) {
                    getLogger().debug("IsUserLoggedAction: no request object");
                    return null;
                }

                Session session= req.getSession(false);
            if (session == null) {
                    getLogger().debug("IsUserLoggedAction: no session object");
                return null;
                }

                        Object par= session.getAttribute("sessionParameters");
                        if ( par == null ) {
                    getLogger().debug("IsUserLoggedAction: user is not logged");
                                return null;
                        } else {
                    getLogger().debug("IsUserLoggedAction: user is logged");
                        Map map= new HashMap();
                return map;
                        }
                } catch (Exception e) {
            getLogger().debug("IsUserLoggedAction: exception " + e);
                }

                return null;
    }
}

This is the way to use it in the sitemap:

<map:actions>
        <map:action name="is-user-logged"
                src="com.lucamorandini.cocoon.IsUserLoggedAction"/>
</map:actions>

<map:match name="wildcard" pattern="selectchangeform.html">
        <map:act type="is-user-logged">
                <!-- Do something, since user is logged -->
        </map:act>
        <!-- Do something else, since user is NOT logged -->
</map:match>

Best regards,

---------------------------------------------
               Luca Morandini
               GIS Consultant
              [EMAIL PROTECTED]
http://utenti.tripod.it/lmorandini/index.html
---------------------------------------------


> -----Original Message-----
> From: Antonio Gallardo [mailto:[EMAIL PROTECTED]]
> Sent: Monday, December 30, 2002 11:58 AM
> To: [EMAIL PROTECTED]
> Subject: How to control a user already is logged?
>
>
> Hi.
>
> I am trying to implement a control that a user cannot log from another
> computer if he is already logged-in.
>
> Where I can find the info about sessions to check if somebody is already
> logged?
>
> Thanks in advance,
>
> Antonio Gallardo.
>
>
>
>
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
> For additional commands, e-mail:   <[EMAIL PROTECTED]>
>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to