Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Andrew Jardine
Portal Struts action -> Portlet Struts action?
September 30, 2013 7:55 PM
Answer

Andrew Jardine

Community Moderator

Rank: Liferay Legend

Posts: 1080

Join Date: December 22, 2010

Recent Posts

I'm not even sure anymore that what I am trying to do is actually possible. Here is my flow.

1. User goes to sign in page (works)
2. User chooses either Google, Twitter or Facebook OAuth (works)
3. Struts actions via 2 hooks (one for fb, one for tiwtter+google) do the authentication (works)
4. User is forwarded to (custom) Registration page (NOT working)

Alternatively --
5. User chooses to Create Account (works)
6. User is taken to custom create account page (JSP override and struts action override done via 3rd hook) (works)

My issue. I can't figure out how to get the user from the OAuth handlers to the /login/create_account page. Can someone tell me how the hell I am supposed to be able to do this? I'm going crazy trying to get this to work and starting to lose a lot of faith. Please help.

Facebook liferay-hook.xml
1
2<hook>
3    <struts-action>
4        <struts-action-path>/login/facebook_connect_oauth</struts-action-path>
5        <struts-action-impl>com.xxxliferay.auth.facebook.FacebookOAuth</struts-action-impl>
6    </struts-action>   
7</hook>


Twitter + Google OAuth liferay-hook.xml
 1
 2<hook>
 3    <portal-properties>portal.properties</portal-properties>
 4    <custom-jsp-dir>/custom_jsps</custom-jsp-dir>
 5    <struts-action>
 6        <struts-action-path>/portal/twitter_login</struts-action-path>
 7        <struts-action-impl>com.mercatus.liferay.auth.twitter.TwitterOAuth</struts-action-impl>
 8    </struts-action>
 9    <struts-action>
10        <struts-action-path>/portal/google_login</struts-action-path>
11        <struts-action-impl>com.mercatus.liferay.auth.google.GoogleOAuth</struts-action-impl>
12    </struts-action>
13</hook>


Custom Create Account liferay-hook.xml
1
2<hook>
3    <custom-jsp-dir>/custom_jsps</custom-jsp-dir>
4    <struts-action>
5        <struts-action-path>/login/create_account</struts-action-path>
6        <struts-action-impl>com.mercatus.liferay.auth.login.action.SproutsCreateAccountAction</struts-action-impl>
7    </struts-action>   
8</hook>


Trace I get in the log --
02:42:28,490 DEBUG [http-bio-8080-exec-268][RequestProcessor:172] Processing a 'GET' for path '/portal/layout'
02:42:28,491 DEBUG [http-bio-8080-exec-268][RequestProcessor:267] Looking for Action instance for class com.liferay.portal.action.LayoutAction
02:42:28,491 TRACE [http-bio-8080-exec-268][RequestProcessor:281] Returning existing Action instance
02:42:28,557 DEBUG [http-bio-8080-exec-268][PortletRequestProcessor:483] Getting request parameter path /login/create_account
02:42:28,558 DEBUG [http-bio-8080-exec-268][PortletRequestProcessor:505] Processing path /login/create_account
02:42:28,559 DEBUG [http-bio-8080-exec-268][RequestProcessor:172] Processing a 'GET' for path '/login/create_account'
02:42:28,561 DEBUG [http-bio-8080-exec-268][RequestProcessor:267] Looking for Action instance for class com.liferay.portlet.login.action.CreateAccountAction
02:42:28,561 TRACE [http-bio-8080-exec-268][RequestProcessor:281] Returning existing Action instance
02:42:28,562 ERROR [http-bio-8080-exec-268][PortletRequestProcessor:453] Forward does not exist
02:42:28,564 DEBUG [http-bio-8080-exec-268][StrutsUtil:57] Forward URI /common/themes/portal.jsp
02:42:28,565 DEBUG [http-bio-8080-exec-268][StrutsUtil:72] Forward path /html/common/themes/portal.jsp

Code I am trying to use to get the user there (in GoogleOAuth class)
 1
 2PortletURL createAccountURL = PortletURLFactoryUtil.create( request, PortletKeys.LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE );
 3
 4createAccountURL.setWindowState( WindowState.MAXIMIZED );
 5createAccountURL.setPortletMode( PortletMode.VIEW );
 6
 7createAccountURL.setParameter( "saveLastPath", "0" );
 8createAccountURL.setParameter( "struts_action", "/login/create_account" );
 9createAccountURL.setParameter( "firstName", firstName );
10createAccountURL.setParameter( "lastName", lastName );
11createAccountURL.setParameter( "emailAddress", emailAddress );
12createAccountURL.setParameter( "googleId", googleId);
13createAccountURL.setParameter( "googlePlusLink", googlPlusLink);
14                        
15redirect = createAccountURL.toString();
16                           
17response.sendRedirect( redirect );
Mohammed Azam
RE: Portal Struts action -> Portlet Struts action?
September 30, 2013 11:19 PM
Answer

Mohammed Azam

Rank: Regular Member

Posts: 159

Join Date: November 6, 2009

Recent Posts

Hi Andrew


What I could understand from your question is that you want to redirect to page of Login from your custom Controller class.

You can use the below code for redirection. Change the "sturts_action" value accordingly
1
2                  PortletURL loginURL = LoginUtil.getLoginURL(
3                request, themeDisplay.getPlid());
4            loginURL.setParameter("struts_action", "/login/userlogin");
5            loginURL.setParameter("login", login);
6
7            redirect = loginURL.toString();
8                      actionResponse.sendRedirect(redirect);


Hope this helps!
Andrew Jardine
RE: Portal Struts action -> Portlet Struts action?
October 1, 2013 5:34 AM
Answer

Andrew Jardine

Community Moderator

Rank: Liferay Legend

Posts: 1080

Join Date: December 22, 2010

Recent Posts

Hi Mohammed,

Thanks for taking the time to write back. That was not quite it but I have managed to solve my problem. My issue was that I kept getting Forward does not exist when transitioning from the /portal/_login struts action to the /login/create_account struts portlet action. I thought maybe that this meant that you couldn't do that but careful debugging led me to a different solution. My custom create account action was EXTENDING BaseStrutsPortletAction. As such I had not overridden the render method and so it was trying to forward to "null". I changed this ti use the StrutsPortletAction interface and then for the render method did the originalStrutsPortletAction.render( ... );. Problem solved.

Thanks again.

Mohammed Azam:
Hi Andrew


What I could understand from your question is that you want to redirect to page of Login from your custom Controller class.

You can use the below code for redirection. Change the "sturts_action" value accordingly
1
2                  PortletURL loginURL = LoginUtil.getLoginURL(
3                request, themeDisplay.getPlid());
4            loginURL.setParameter("struts_action", "/login/userlogin");
5            loginURL.setParameter("login", login);
6
7            redirect = loginURL.toString();
8                      actionResponse.sendRedirect(redirect);


Hope this helps!