Message Boards

Customizing Logout Event in Liferay 7.1

Sami Ullah, modified 5 Years ago.

Customizing Logout Event in Liferay 7.1

New Member Posts: 14 Join Date: 9/28/15 Recent Posts
Hi,

I have implemented "logout.events.post" according to this post https://www.learnandpost.com/2016/08/portal-events-in-liferay.html but I'm not able to get user to redirect to login page, I have multiple sites and each one have its on login page, after logout user should be redirected to login page of that site but its getting redirected to default "/web/guest/login" page.


Here is my code.

@Component(
    immediate = true,
    property = {
        "key=logout.events.post"    
    },
    service = LifecycleAction.class
)
public class CustomLogoutAction implements LifecycleAction {

    private static final Log log = LogFactoryUtil.getLog(CustomLogoutAction.class);
    @Override
    public void processLifecycleEvent(LifecycleEvent lifecycleEvent)
        throws ActionException {
        HttpServletRequest request = lifecycleEvent.getRequest();
        HttpServletResponse response = lifecycleEvent.getResponse();
        
        try {
            String loginPage = request.getParameter("login");
            if (loginPage != null && !loginPage.isEmpty()) {
                response.sendRedirect(loginPage);
            }            
            
        } catch (Exception e) {            
            e.printStackTrace();
        }
    }

}



I understand that it gives me null against login parameter because liferay does loses context for current group at post this event & I also tried this with "logout.events.pre" event but same result. Is this the only way to do this in liferay 7.1 ?