Search code examples
fragmenthookliferay-7liferay-dxp

How to redirect User to website specific landing page


I wanted to redirect user to default landing page based on the website access user has in liferay. I am using liferay DXP. I know how it can be done in liferay 6.2, but i don't have a idea how to override/extend DefaultLandingPageAction class in liferay 7.

Let me know if anybody has done this before.

Thanks!!


Solution

  • I assume that you are trying to redirect the user after login.

    Have a look at this. Should do the trick. Place the class into a bundle and adjust the logic.

    @Component(
          immediate = true,
            property = {
                    "key=login.events.post"
            },
            service = LifecycleAction.class
    )
    public class LandingPageRouter implements LifecycleAction {
        private static Log LOG = LogFactoryUtil.getLog(LandingPageRouter.class);
    
        @Reference
        private UserLocalService userLocalService;
    
        @Override
        public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {
           //Do some magic
    
           //build the path.
           LastPath lastPath = new LastPath(StringPool.BLANK, path);
           lifecycleEvent.getRequest().getSession().setAttribute(WebKeys.LAST_PATH, lastPath);
        }
    }
    

    LastPath works as in DefaultLandingPageAction.