Liferay Portal 7.2 GA2 - Redirect user to Site

Francesco Francesco, modified 5 Years ago. New Member Posts: 2 Join Date: 7/25/20 Recent Posts
Hi,
on Liferay Portal 7.2, I should redirect to my home site after logging in. Is there a way? i tried with the landing page but as they are filtered as only $ screenname and $ userid.
In practice I should redirect certain people on one site and others on another site
Thank you all
thumbnail
Christoph Rabel, modified 5 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
We usually add our own post login action to do that.
I cut a bit of sample code out of one of our modules to give you an idea how it would look like. If the logic isn't too complicated, it should be easy enough to implement.
@Component(
    immediate = true, property = {"key=login.events.post"},
    service = LifecycleAction.class
)
public class MyRedirectAction implements LifecycleAction {
    @Override
    public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {
        User user = null;
        try {
            user = PortalUtil.getUser(lifecycleEvent.getRequest());
        } catch (PortalException e) {
            throw new ActionException(e);
        }
       String redirectURL = getRedirectURL(user);
       if (redirectURL != null) {
            try {
                lifecycleEvent.getResponse().sendRedirect(redirectURL);
            } catch (IOException e) {
                throw new ActionException(e);
            }
        }
    }
}