Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Günther P
Hide page for authenticated users
August 16, 2011 11:48 PM
Answer

Günther P

Rank: New Member

Posts: 12

Join Date: August 1, 2011

Recent Posts

Hi,

I want to show a page to not authenticated users but want hide this page as soon as you are logged in. When I give view permissions to the Guest role, everybody can access the page - authenticated and unauthenticated users. So is there a way to configure the permissions to deny access to authenticated users (which also hides the related navigation entry)?

Thanks in advance,
Günther
Jignesh Vachhani
RE: Hide page for authenticated users
August 17, 2011 3:58 AM
Answer

Jignesh Vachhani

Rank: Liferay Master

Posts: 772

Join Date: March 10, 2008

Recent Posts

if i understand correct you want to give page permission for logged in user only right ??????
Günther P
RE: Hide page for authenticated users
August 17, 2011 4:30 AM
Answer

Günther P

Rank: New Member

Posts: 12

Join Date: August 1, 2011

Recent Posts

No, actually the other way around - only unauthenticated users should see one specific page and the related navigation entry.
Jignesh Vachhani
RE: Hide page for authenticated users
August 17, 2011 5:30 AM
Answer

Jignesh Vachhani

Rank: Liferay Master

Posts: 772

Join Date: March 10, 2008

Recent Posts

ohh ok then i think this is not the way i think you can configure because any authenticated user can see those pages after logout.
So there is no meaning to make it hide for logged in user. Am i right ?

Still if you want to do it then you have to make changes in navigation and page permission logic that would be very risky and not proper way to do.
Rob Chan
RE: Hide page for authenticated users
August 17, 2011 10:02 AM
Answer

Rob Chan

Rank: Junior Member

Posts: 82

Join Date: March 23, 2011

Recent Posts

Go to the page you want to hide for authenticated users, and go to the top bar.

Click Manage > Page. When the next screen loads, scroll to the bottom and click "Permissions."

Unclick the "view" check box for everyone but "guest" and "admin" so that you can still manage it.

This should do the trick.
Sagar A Vyas
RE: Hide page for authenticated users
August 17, 2011 11:54 AM
Answer

Sagar A Vyas

Rank: Liferay Master

Posts: 634

Join Date: April 17, 2009

Recent Posts

So is there a way to configure the permissions to deny access to authenticated users


Hi Gunther,

You can definitely hide some to some set of user by giving him specific role.

But by reading you requirement i have one Question .

1) To Whom you are called authenticate user ? (Admin ?)

" User A can see Page A - That means user A is authenticate for Page A "

I requesting you to please elaborate more on your requirement.

Thanks,
Sagar Vyas
Günther P
RE: Hide page for authenticated users
August 17, 2011 3:24 PM
Answer

Günther P

Rank: New Member

Posts: 12

Join Date: August 1, 2011

Recent Posts

@Rob - I tried this first but this is not working for me. Maybe that would have been too easy emoticon

@Jignesh - yeah, I also would prefer a solution which only needs some configuration, but I am not sure if you really understand what I need.


Let me give an example:

Community "A" has page "Guest information".
User "Alice" (no admin, but power user) is assigned to community "A".
Every guest user, who is not signed in, should see the page "Guest information". (So assign "VIEW" permission to "Guest" I assume?)
As soon as a "Alice" is signed in, the page "Guest information" should not be accessible anymore for "Alice". Of course after logout, page "Guest information" appears again.

Hope that makes my requirements more clear?!

Greets,
Günther
Abhed Dekavadiya
RE: Hide page for authenticated users
August 18, 2011 4:52 AM
Answer

Abhed Dekavadiya

Rank: Junior Member

Posts: 67

Join Date: October 5, 2010

Recent Posts

Günther P:
@Rob - I tried this first but this is not working for me. Maybe that would have been too easy emoticon

It won't work because with liferay's default permission mechanism, everyone inherits guest permissions.

This post could help: http://www.liferay.com/community/forums/-/message_boards/message/2466521

In short this is not possible by only configuration changes.

Below are possible solutions:
(1) code change
Modify the navigation.vm file to handle display of "Guest Information" page for not-signed-in users only.

(2) Just a thought on "Only Configuration changes solution" (a loud solution & I haven't tried this & I don't recommend this ):
If you want to achieve this only with configuration, then you can try the approach of community switching with "Default Landing Page" and "Default Logout Page" settings.
"Control Panel" -> Settings -> "Default Landing Page" = /web/A/home
"Control Panel" -> Settings -> "Default Logout Page" = /web/guest/home
In guest community create the page "Guest Information" and NOT in "A" community. Common pages (visible to both non-authenticated & authenticated users) needs to be created in both community.
Problems: Won't work when communities will have 'virtual host' configured, Maintenance of duplicate common pages, etc...
Günther P
RE: Hide page for authenticated users
August 18, 2011 9:47 AM
Answer

Günther P

Rank: New Member

Posts: 12

Join Date: August 1, 2011

Recent Posts

Thanks Abhed, I changed navigation.vm and it works as required. I don't know if $user.isDefaultUser() is the correct way to check if the current user is signed in or not in the Theme (other suggestions appreciated), but the following works:

1        #foreach ($nav_item in $nav_items)
2            #if(!$nav_item.getName().equals("Guest information") || $user.isDefaultUser())
3                            // render the navigation
4            #end
5        #end

Of course you can still open "Guest information" via the URL but as it is available for guest users anyways, so I can go with that. At least it is not visible in navigation anymore.
Victor Zorin
RE: Hide page for authenticated users
August 18, 2011 2:05 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1173

Join Date: April 14, 2008

Recent Posts

Use $is_signed_in, e.g.
#if($is_signed_in)
<li><a href="/c/portal/logout">Sign Out</a></li>
#else
<li><a href="/c/portal/login">Sign In</a></li>
#end
Abhed Dekavadiya
RE: Hide page for authenticated users
August 18, 2011 11:53 PM
Answer

Abhed Dekavadiya

Rank: Junior Member

Posts: 67

Join Date: October 5, 2010

Recent Posts

Hi Günther,

I would say $user.isDefaultUser() is not the recommended/correct way to check if user is signed-in or not.
$theme_display.isSignedIn() is the recommended way.

Your mentioned check will work because liferay has an actual user in the database for Guest user (anonymous user). And the flag 'isDefaultUser' is set to true for this user. This user is created along with liferay database, when you first time start Liferay (portal-data-sample.vm).
When none is signed in (user is null) liferay renders with the default user. This is how liferay is designed, it needs an user to render !!
So it's like, a default user is always not-signed-in user. In fact, when you set the flag default-user = true for any other user, liferay doesn't allow to login.

Your check in navigation.vm could be like this
1
2#foreach ($nav_item in $nav_items)
3            #if(!$nav_item.getName().equals("Guest information") || !$is_signed_in)
4                            // render the navigation
5            #end
6#end


regards,
Abhed
Günther P
RE: Hide page for authenticated users
August 19, 2011 2:20 AM
Answer

Günther P

Rank: New Member

Posts: 12

Join Date: August 1, 2011

Recent Posts

Thanks guys, i replaced $user.isDefaultUser() with !$is_signed_in and it is working fine.

Greets,
Günther
Shankar Baba
RE: Hide page for authenticated users
November 22, 2012 11:48 PM
Answer

Shankar Baba

Rank: Regular Member

Posts: 144

Join Date: October 17, 2012

Recent Posts

Günther P:
Thanks Abhed, I changed navigation.vm and it works as required. I don't know if $user.isDefaultUser() is the correct way to check if the current user is signed in or not in the Theme (other suggestions appreciated), but the following works:

1        #foreach ($nav_item in $nav_items)
2            #if(!$nav_item.getName().equals("Guest information") || $user.isDefaultUser())
3                            // render the navigation
4            #end
5        #end

Of course you can still open "Guest information" via the URL but as it is available for guest users anyways, so I can go with that. At least it is not visible in navigation anymore.



Hi Gunther, this is't worked for me could u please tell me how u have achieved this , and what u have written the code for // render the navigation, i am strucking here, need help.

Regards,
Shivaji