Forums de discussion

Redirect to login from Action

jonathan doklovic, modifié il y a 13 années.

Redirect to login from Action

Junior Member Publications: 25 Date d'inscription: 13/04/10 Publications récentes
Hi,

I have a portlet that has multiple actions.
One of these actions is linked to from guest available page, but requires an authenticated user.

How can I check if the user is logged in, and if not, redirect to login and have it redirect back to the action with the original parameters? Again, I need to do this from within and action, not a jsp.

Thanks.
Anshul Gupta, modifié il y a 13 années.

RE: Redirect to login from Action

Regular Member Publications: 114 Date d'inscription: 05/02/10 Publications récentes
Check the isSignedIn() method in ThemeDisplay.java. You have to get the user first either through PotalUtil object or ThemeDisplay object and then you can check if user is signed in and get required information.

Thanks
Anshul
jonathan doklovic, modifié il y a 13 années.

RE: Redirect to login from Action

Junior Member Publications: 25 Date d'inscription: 13/04/10 Publications récentes
Easy enough to get the user, but if not logged in, how do i do the redirect properly to the login form and have it redirect back?
thumbnail
Amos Fong, modifié il y a 13 années.

RE: Redirect to login from Action

Liferay Legend Publications: 2047 Date d'inscription: 07/10/08 Publications récentes
You may want to take a look at portal/action/LoginAction.java

Probably do something like this:

PortletURL portletURL = new PortletURLImpl(
request, PortletKeys.LOGIN, themeDisplay.getPlid(),
PortletRequest.RENDER_PHASE);

portletURL.setWindowState(WindowState.MAXIMIZED);
portletURL.setPortletMode(PortletMode.VIEW);

portletURL.setParameter("saveLastPath", "0");
portletURL.setParameter("struts_action", "/login/login");
portletURL.setParameter("redirect", [currentURL])

response.sendRedirect(redirect);
thumbnail
Rajesh Babu, modifié il y a 13 années.

RE: Redirect to login from Action

Regular Member Publications: 161 Date d'inscription: 08/02/10 Publications récentes
HI Amos,

i followed the same approach for redirection, but i m getting error like can not find symbol for PortletURLImpl.

i had imported the foll for PortletURLImpl.

import com.sun.portal.portletcontainer.portlet.impl.PortletURLImpl;

Plz suggest where i m getting deviated to error.
thumbnail
Peter Shin, modifié il y a 13 années.

RE: Redirect to login from Action

Regular Member Publications: 121 Date d'inscription: 24/09/07 Publications récentes
PortletURLImpl isn't accessible from plugins. Try this instead:

<%
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));
%>
Tam Nguyen Minh, modifié il y a 13 années.

RE: Redirect to login from Action

New Member Publications: 16 Date d'inscription: 01/12/10 Publications récentes
Hi everyone,

I intend to create my own login portlet. I got the authentication by using UserLocalServiceUtil.authenticateByEmailAddress (UserLocalServiceUtil.authenticateByScreenName)and put my login information to Session & Cookie (Just like LoginUtil in liferay) but I can't find the way to get in portal with my acc that i do the authentication. Are there something wrong or i'm missing something ? Please help T_T
I'm newbie so I use MVC Portlet not Struts Portlet

Thanks in advanced,
Tam Nguyen
Koen Cleynhens, modifié il y a 13 années.

RE: Redirect to login from Action

Junior Member Publications: 83 Date d'inscription: 23/02/10 Publications récentes
Did you be able to manage it?