Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Alexander Topalov
Explicit redirect to the login page
29. März 2013 08:05
Antwort

Alexander Topalov

Rang: New Member

Nachrichten: 2

Eintrittsdatum: 29. März 2013

Neue 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:
1
2ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
3LiferayPortletURL liferayPortletURL = PortletURLFactoryUtil.create(request, PortletKeys.LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);
4liferayPortletURL.setWindowState(WindowState.MAXIMIZED);
5 liferayPortletURL.setPortletMode(PortletMode.VIEW);
6 liferayPortletURL.setParameter("saveLastPath", "0");
7 liferayPortletURL.setParameter("struts_action", "/login/login");
8 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.
Amos Fong
RE: Explicit redirect to the login page
2. April 2013 12:09
Antwort

Amos Fong

LIFERAY STAFF

Rang: Liferay Legend

Nachrichten: 1898

Eintrittsdatum: 7. Oktober 2008

Neue 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
RE: Explicit redirect to the login page
3. April 2013 00:04
Antwort

Alexander Topalov

Rang: New Member

Nachrichten: 2

Eintrittsdatum: 29. März 2013

Neue 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 -
1session.enable.phishing.protection=false

so that after login the user keeps the same session.