How to configure Plone to redirect to come_from after logout

I want to set up a plone site to redirect to the came_from parameter in the url after the user logs out. For login, I installed string:${globals_view/navigationRootUrl}/login?came_from=${context/absolute_url}

and it works.

It doesn't work for logging out. I also tried with my event:

  <subscriber
    for="Products.PlonePAS.events.UserLoggedOutEvent"
    handler="blabla.goCameFromAfterLogout"
    />

      

through:

def goCameFromAfterLogout(event):
    """ Redirects user to came_from url parameter after logout
    """
    import pdb; pdb.set_trace( )
    request = event.object.REQUEST
    came_from = request.form.get('came_from', None)
    if came_from:
        response = request.RESPONSE
        response.redirect(came_from)

      

The event is ok, the come_from parameter is ok, but the code doesn't work as I want. The website redirects me /logged_out

every time.

So how can I fix this?

+3


source to share


3 answers


The easy way: customize logged_out

, convert it to Python Script that redirects to whatever page you want:



context.REQUEST.RESPONSE.redirect(url)

      

+6


source


You can also create a redirect exception in your event handler



from zExceptions import Redirect

def goCameFromAfterLogout(event):
""" Redirects user to came_from url parameter after logout
"""
request = event.object.REQUEST
came_from = request.form.get('came_from', None)
if came_from:
    raise Redirect(came_from)

      

+2


source


Also ?next=url

instead of come_from is a good idea.

+1


source







All Articles