Forums de discussion

getting current URL in login.events.post class

juan meza, modifié il y a 8 années.

getting current URL in login.events.post class

Regular Member Publications: 228 Date d'inscription: 06/01/14 Publications récentes
Hi, I have Liferay 6.2GA4

I created a class that loads after the login event:
login.events.post=org.iad.login.liferay.hook.LandingPageAction

in this LandingPageAction, i want to do some logic, to redirect the user to a site according to certain rules...
i have many sites, with many login pages each in their public pages... so i want to know from wich site they are trying to login... is there a way to know this?

i've tried getting the currentURL from request (request.getRequestURI() and request.getRequestURL())... but it always gives me "/c" as URL, no mather wich site they are logging in from...

how can i know the current URL? or the site friendly URL? or something so i can know wich site they are logging in from?


thank you!
thumbnail
Kailash Yadav, modifié il y a 8 années.

RE: getting current URL in login.events.post class (Réponse)

Regular Member Publications: 211 Date d'inscription: 18/10/11 Publications récentes
juan meza:
Hi, I have Liferay 6.2GA4

I created a class that loads after the login event:
login.events.post=org.iad.login.liferay.hook.LandingPageAction

in this LandingPageAction, i want to do some logic, to redirect the user to a site according to certain rules...
i have many sites, with many login pages each in their public pages... so i want to know from wich site they are trying to login... is there a way to know this?

i've tried getting the currentURL from request (request.getRequestURI() and request.getRequestURL())... but it always gives me "/c" as URL, no mather wich site they are logging in from...

how can i know the current URL? or the site friendly URL? or something so i can know wich site they are logging in from?


thank you!

Try to get LAST_PATH from session. Try following code to find what values you can get there emoticon
@Override
	public void run(HttpServletRequest request, HttpServletResponse arg1)
			throws ActionException {
		Enumeration<string> attributeNames = request.getAttributeNames();
		while (attributeNames.hasMoreElements()) {
			String string = (String) attributeNames.nextElement();
			System.out.println(string + " &gt;&gt;&gt; " + request.getAttribute(string));
		}
		
		HttpSession session = request.getSession();
		Enumeration<string> attributeNames2 = session.getAttributeNames();
		while (attributeNames2.hasMoreElements()) {
			String string = (String) attributeNames2.nextElement();
			System.out.println(string + " &gt;&gt;&gt;&gt;&gt;&gt;&gt; " + session.getAttribute(string));
		}
		
	}</string></string>

Hope it will help !
deveshree zawar, modifié il y a 8 années.

RE: getting current URL in login.events.post class

Junior Member Publications: 61 Date d'inscription: 09/02/16 Publications récentes
Hi,

Along with the above post you can also use the PortalUtil API method as follows :

 
@Override
&nbsp;&nbsp;public void run(HttpServletRequest request, HttpServletResponse response) {
&nbsp;&nbsp;&nbsp;&nbsp;String CurrentPortalUrl = PortalUtil.getCurrentURL(request).toLowerCase();
&nbsp;&nbsp;&nbsp;&nbsp;String redirectURL = "Friendly URL" //Friendly Url of your site
&nbsp;&nbsp;&nbsp;&nbsp;/** You business logic on which redirect URL value will be updated **/
&nbsp;&nbsp;&nbsp;&nbsp;response.sendRedirect(redirectURL);
&nbsp;&nbsp;
&nbsp;&nbsp;}

Hope it will help!

Thanks,
Deveshree
juan meza, modifié il y a 8 années.

RE: getting current URL in login.events.post class

Regular Member Publications: 228 Date d'inscription: 06/01/14 Publications récentes
thank you guys!! really helpful!

LAST_PATH from request was the answer i was looking for!!

on a special note, LAST_PATH is not a String!, i tried it at first and did it work... it is an object... LastPath is the object and the .toString() method does not give you the answer.. you have to parse it and get the attributes inside.. in case someone has the same dumb problem... emoticon