4

I need that if a user is already login and he manually enters login path he redirects to home page?.Please let me know how to how to perform this.

Thanks

dhruv
  • 41
  • 2
  • ok.. i came to know that browser back button shows cached page so filter can't work.Now i am wondering how to clear cache in liferay – dhruv Feb 08 '13 at 12:38

2 Answers2

1

As far as I understand you want that even after login if you enter the following sign-in URL:

http://localhost:8080/web/guest/home?p_p_id=58&p_p_lifecycle=0&p_p_state=maximized&p_p_mode=view&saveLastPath=0&_58_struts_action=%2Flogin%2Flogin

then you should be taken to the home page i.e. to http://localhost:8080/web/guest/home.

So if this is the case then I think you can create a servlet-filter hook which would intercept all requests and check for the relevant parameters of the URL such as struts_action=/login/login and do the following (in psuedo code):

if(is_SignIn_URL) { // check if it is the sign-in URL

    if(isUserLoggedIn) { // check if user is logged-in

        // redirect to the home page configured in portal-ext.properties

    } else {

        // let the application work normally i.e. let it go to the sign-in page

    }
}

Also for information and in-depth understand you can check lifeary's AutoLoginFilter class (this is an actual Servlet-filter but you can make a hook along the same lines) and liferay-web.xml for the URL c/portal/login which takes you to the home page if the User is logged-in or else takes you to the sign-in page.

And this is independent of using a Cookie :-)

Prakash K
  • 11,537
  • 5
  • 49
  • 107
  • Thanks @Prakash K.I tried Filters but i am problem 1)It seems that doFilter function is called exh time a new url is hit.But when i login and press back button after that it doesnot seems to be called.Is there a specific reason for that? – dhruv Feb 08 '13 at 10:18
  • i forgot to mention i am using my custom portet that is on http://localhost:8080 .So when user is logedin and he hits back or manually enters http://localhost:8080 he should redirect to http://localhost:8080/web/test/home. – dhruv Feb 08 '13 at 10:46
  • @user2051495 You can instruct the Browser not to Cache. Refer this [http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers](post). But it will affect performance of your page load! And, also User might click Back button on "any" of the pages on your site. So, you ll end up clearing cache in many pages. This will be a performance bottleneck – Vikas V Feb 08 '13 at 13:34
  • @Prakash K Filter you have referred to is for Liferay V.6.1 Any other options for versions lower than that? Like version 6.0 ? – Vikas V Feb 08 '13 at 13:56
  • @Vikas thanks so is there a sollution that doesnot cause performance issues.Now for some time i have been experimenting with javascript but cant find a solution – dhruv Feb 08 '13 at 14:47
0

You can write a Redirection rule in your web server. Example code below in Apache httpd.conf file,

Create a Cookie (lets say yourCookie) as soon as you login.

RewriteEngine On
RewriteCond %{HTTP:Cookie}  yourCookie=([a-zA-Z0-9]+)
RewriteCond %{REQUEST_URI} ^/web/portal/home/-/portal/login/      //This is your login page URL
RewriteRule .* http://%{SERVER_NAME}/web/portal/home [R=302]      //This is your Home Page URL
Vikas V
  • 3,128
  • 2
  • 30
  • 59
  • Thanks @Vikas V.I will try that and let me know is there any other way if i dont want to use cookies? – dhruv Feb 08 '13 at 04:39