[Solved] IUserLoggedInEvent - Not able to redirect


I want to redirect users according to their group membership. Therefore I added the code found here: https://docs.plone.org/develop/plone/sessions/login.html#post-login-actions to my addon and modified it a bit.
Using logging I can see that it gets executed after every login but the redirect does not work. Even if I use request.response.redirect(url, lock = True). How can I convince Plone to redirect to the URL I want after every login?

Have you checked this?

We are running it in Plone 4.3. We configured a redirection to a custom browser view that performs some redirection based on some user constrains like group membership or roles.

We are running Plone 5.2 and Python 3.8. Sorry, I thought the tags were enough to make that clear. collective.onlogin seems not be tested on Plone 5 or Python3.

He probably meant looking at the code and see what collective.onlogin does.

For example, it uses request.RESPONSE.redirect (https://github.com/martinschoel/collective.onlogin/blob/024a6e1aab943270d9537bde16fbbff6b4521f4c/src/collective/onlogin/events.py#L77) and two event handlers https://github.com/martinschoel/collective.onlogin/blob/024a6e1aab943270d9537bde16fbbff6b4521f4c/src/collective/onlogin/configure.zcml#L30-L40.

Maybe these two handlers are what you need to do as well?

You can use plone.login. Works on Plone 5.

plone.login was merged into Products.CMFPlone in 5.2.

Look at

So implementing a IRedirectAfterLogin multi adapter bound to your browser layer (which is an interface on the request) returning an url to redirect to on call will do it.

1 Like

That sounds promising. Could you show me a minimal example of that, please?

It seems it is only documented in the Upgrade Guide here https://docs.plone.org/manage/upgrading/version_specific_migration/upgrade_to_52.html#new-login

We definitely need to move/copy this information to a better place docs.plone.org, any takers?


This works great. Thank you!

I am looking for such a solution, can you share the complete implementation?

@Heiko It is just what you can see behind the link of @jensens.
The __call__ method has to return the address you want to redirect to.

Plone Foundation Code of Conduct