How to dynamically hide/remove some menus from navigation? - plugins

I'm working on a wordpress plugin which inserts some pages using wp_insert_post() on activation. These pages are then used for different purposes (user account dashboard, edit account info, change password, login, logout, etc...).
Issue is all these pages get some menus which are displayed to all frontend users which is not correct because a non logged-in user for example should not see logout menu or any menu to a private page until authenticated. Now, I'm stucked at how to do just that. Any idea ?
I stress that the plugin login process is seperated from WP login

Wordpress can not assign restrictions and roles to specific pages, posts or terms by default.
You could create two separated menues and add a custom logic to your template.
if(is_user_logged_in())
{
wp_nav_menu('foo');
}
else
{
wp_nav_menu('bar');
}

Related

Page Access for anonymous user and with a specific group

I have a page: /events/
(a) If the user is not logged in, i want him to see a login
-> Result: Page is visible for all + Login-Element on page (with: hide on login)
(b) If the user is in the usergroup eventuser, he should see an event-plugin on the page
-> Events-Plugin is on page (with group permission: eventuser)
Everything cool for those two guys.
But if the user is a normal logged-in user (without the group eventuser) the page /events/ is empty.
How can i create a page which is accessible for anonymous users (to show a login) and is visible in the navigation for eventusers but not for standard fe_users?
Create two pages on the same level.
The first one is accessible for everyone (with "hide on login" set), the second one is accessible for the eventuser group only.
Create your login plugin on the publicly available page and set a redirect to the restricted page on successful login.
Create your event plugin on the access restricted page.
Now you need to set a redirect page for your other groups (or the other way around) after successful login, so all other groups, except eventuser will get redirected somewhere else. They won't see the events page at all.
hth
You need to create two user group eventuser and websiteuser.
Now you can redirect user on specific page using redirect option in group configuration.
If user assign websiteuser gruop then you can redirect it's your site home page and eventuser group redirect to event page.
See below screenshot.

CQ5.6 - CUG enabling for protecting pages breaks other components

We have implemented login functionality like geometrixx site in our existing website(with close to 700+ pages).
We want to show protected pages only to logged in user, every user who is registered gets assigned a group/ CUG lets say "listed users".
now in page hierarchy I have products page and under product page I have 8 products pages.somewhere On homepage I have a nav bar component which fetches all product children pages and shows a left nav bar with 8 entries.
If I enable CUG in a way that only "listed users" should have access to 2 out of 8 product pages, any access to direct links are redirected to login page. Which is fine.
But the nav bar component which earlier used to show all 8 product pages now shows only 6 pages.
The main idea behind putting pages behind login is lead generation.So if non logged in users dont see the link itself where would they click to get redirected to login page and subsequently feel like registering with our site.
Requirement is that my existing nav bar should continue showing 8 links and on click of 2 protected page links, he should get login/ register option.
We are using most of things Out of the Box.
any pointers helping in how do we achieve this would be great help ? PS: i have given a nav bar as one such component affected in existing site like this there could be many more components fetching their content from site hierarchy and stand chance to get broken in such case.
There are two entities involved, JCR and Sling.By default any un-authenticated request is associated with a user called Anonymous, the JCR sessions will have ACL's associated with anonymous.
In JCR, if a user does not have access to nodes, that session will not see those nodes.We access the JCR via Sling ,by default if you don't have permission the request will result in a 404 error(because for underlying JCR session the resource does not exist). Sling can be explicitly instructed to request for authentication for specific paths.
The combination of these concepts are leveraged to create the CUG functionality. Sling is instructed to force for authentication for CUG enabled pages. The JCR is instructed to show these nodes only for users who have access.
When you directly request the product pages without login, it is sling that is redirecting you to login page. When your navigation component is looping over nodes to create the menu for anonymous users JCR is only showing it 6 pages as the other two are out of reach for anonymous.
The only* way to work around this is to make the Navigation component configurable. Instead of node iteration, the content author will have to configure the the url and page title so that the links show up for everyone.
You can ignore the session associated with the request and use a custom JCR session that has access to all the product pages, but that would be disregarding the ACLs and you don't want to do that .
The nav bar can pick up all child pages as per page structure. That should not restrict the page title display on the nav bar.
As for the pages the access can be controlled by template level page properties by adding the 'listed users' group over there. In the jsp you can give an initial check for the user if they are a member of 'listed users' else redirect to login page
Hope that helps
Thanks for all your suggestions
Below is how we ended up doing it.
- Protect the page you want to enable CUG with proper CUG.
- Hide the page in nav.
- Create a redirect page in same hierarchy with same title as the one you wanted to protect.redirect it to your protected page.

moodle first time login redirect to custom page

I have moodle site with custom signup page when new user register user redirect to the home page but then it automatically redirect to the profile edit page which is at(http://www.test.con/user/edit.php?id=46&course=1) once i update profile i can go to home page.so i want to stop this and redirect to home page.
The automatic redirect happens when a user has required fields in their profile that still need to be completed.
Maybe you could make all required profile fields required fields in your custom signup page too, then users will always have completed them already by the time they log in for the first time.
I think it is related to the configuration of "Default home page for users":
Go to Site Administration => Appearence => Navigation
Select other option other than "User preference".
Hope that helps!

Page we need to choose to override for Custom User Registration in Liferay 6.1 among these two?

I am in need of override the User registeration page inside the Liferay .
My requirement is that i need to add a Password and password confrmation field to it to the newly created user .
Before creating a hook to modify the jsp and the UserLocalService , i have got a below query
I have seen two user registration screens which are
a screen popped up when navigated through Sign -In ---->Create_account Page
Control Panel ---> User and Organization ---> Add User Page
Could anybody please let me know what is the page i need to choose from the above two ??
Also please let me know what is the difference between these two screens ??
Option 1 is for scenario when any guest user comes to your site and do registration.
Option 2 is screen where admin user creates user.
For user registration customization, you have to override create_account.jsp from sign in portlet.(option 1)

Liferay: Role that can add web content only in certain pages of the site

Is it posible to define a role which can only create/read/update/delete web content in certain pages of the site? For example the role "NewsContent" can only add web content to the news page (and it's subpages).
I couldn't achieve this so far since I don't see anything like this in when adding permissions to a role. I can set the "Add web content" permission to a role but with this permission the users with this role will be able to add web content in all the pages of the site.
I hope that this is posible since this feature is very important for my application.
Thanks in advance!
Do you have Portlets in your application? If so, below solution which is for JSF based portlets can be of help.
As per my understanding "NewsContent" role can only add web content to the news page. So, I guess you have a Portlet which displays news page. In this case, get the role of the user from Liferay DB.
FacesContext context = FacesContext.getCurrentInstance();
javax.faces.context.ExternalContext externalContext = context.getExternalContext();
if(externalContext.isUserInRole("NewsContent"))
{
//Allow this user to do what you want him to do
}
If you are not using JSF based Portlets, you can still make a query to Liferay DB and get the role of the user logged in by querying in USER_, USERS_ROLES and ROLE_ tables.
Go in Control-Panel=>Roles
Select particular role in which you assign the user
select define permission for that role
select site administration
Enable only Manage pages checkbox in site
Now user with that particular role is able to ad web content on a page.
This will resolve your issue.