Foren

Explicit redirect to the login page

Alexander Topalov, geändert vor 11 Jahren.

Explicit redirect to the login page

New Member Beiträge: 2 Beitrittsdatum: 29.03.13 Neueste Beiträge
Hi,
I'm developing an application with ZK 5 on top of Liferay 6.1.0.
I have a portlet that contains a couple of different tabs. The desired workflow is this:
- An anonymous user is allowed to access the 1st tab.
- When he wants to navigate to the 2nd tab, he's redirected to the login page.
- After the user logs in, he's redirected back to the 2nd tab, where he can see the data that he filled in the 1st one.

I am new to Liferay and I have no idea how to explicitly redirect to the login page from the controller (a ZK composer).
Before posting I searched a lot. The best I found is this code:

ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
LiferayPortletURL liferayPortletURL = PortletURLFactoryUtil.create(request, PortletKeys.LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);
liferayPortletURL.setWindowState(WindowState.MAXIMIZED);
 liferayPortletURL.setPortletMode(PortletMode.VIEW);
 liferayPortletURL.setParameter("saveLastPath", "0");
 liferayPortletURL.setParameter("struts_action", "/login/login");
 liferayPortletURL.setParameter("redirect", PortalUtil.getCurrentURL(request));

But it doesn't work, because themeDisplay is null (as far as I understand untill the user actually logs in).
It would also be nice to somehow read the login URL dynamically.
thumbnail
Amos Fong, geändert vor 11 Jahren.

RE: Explicit redirect to the login page

Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
Hi,

This code looks good. ThemeDisplay shouldn't be null even if the user isn't signed in yet. What's the error you get?
Alexander Topalov, geändert vor 11 Jahren.

RE: Explicit redirect to the login page

New Member Beiträge: 2 Beitrittsdatum: 29.03.13 Neueste Beiträge
Hi,
thank you for your reply. ThemeDisplay was null because I am executing this code within a ZK event handler,
i.e. after an Ajax call, that doesn't know anything about the portlet request. I solved this by extending
ZK's default Portlet, explicitly adding the themeDisplay to the session as it is shown here -
http://capitalcode.blogspot.com/2012/09/zk-liferay-integration-first-step.html

For the other part of the issue - to preserve the already entered data after the login redirect - as I can't think of a better way,
again I added it to the session and I also added this property to portal-ext.properties -
session.enable.phishing.protection=false

so that after login the user keeps the same session.