Restrict access to page for anonymous users in Drupal - drupal

Very simple question that i'm stuck with.
I'm making a very simple 'classifieds' website; i have a content-type of type 'classified' i'd like to give access to that content-type for registered users only; i edited the permissions so only 'authenticated' users can 'create classified' and also created a menu link to 'node/add/classified'.
The problem is that when anonymous, i don't see the 'create classified' menu link (right, because the user doesn't have the right to 'create' one) but I still want this menu item to appear and i'm redirecting to my custom 403 page that says 'hey, you have to create an account first before posting a classified'.
What's the best 'elegant' way to achieve this ?

My solution would be to create a new page (via hook_menu) at, say "classified/add". In this page, check the user's id = if it's 0, then display your friendly message about joining the site.
If they aren't 0, then append/return node_add('classified'). (Note that node_add is in node.pages.inc, so you'll want to include that when needed.)

I have actually done the same thing for a classified ad system. Creating absolute URLs as menu items works for me and is quite simple.
For example, instead of making the menu item path 'node/add/classified', set the path to 'http://example.com/node/add/classified'. When you click the menu item when logged out (as anonymous), Drupal will try to go to the create classified page, but will fail the permissions check and redirect to your custom 403 page.

Try creating a new menu item manually (Admin > Site building > Menus > Menu name > Add item), to point to the node/add/classified URL.
Update: You could try linking to /node/403?destination=node/add/classified (where node/403 is your custom 403 error page).

Related

Need a way to gate content on my webpage in Drupal 8

I wanted to gate content on my site using web forms module just like how QUORA/glassdoor does. I would want only logged in users to see all content and non logged in users should be shown a form to fill based on which user should be shown the actual content, have no coding experience. Have a bit of idea on the editor side though.
Please help! Thanks
You can restrict whether content may be viewed by anonymous visitors by changing the setting in /admin/people/permissions > View published content.
By default they will see an "Access denied" message.
There are many ways to achieve redirecting anonymous visitors to a login page or form when they visit a page they don't have access to.
One way would be to use a module like anonymous_login: https://www.drupal.org/project/anonymous_login
Screenshot of Home > Administration > People > Permissions > View published content

Drupal 6: Want to remove access restrictions on a View

I have a View with a Page display that only allows the returned data to be linked if the user is authenticated/logged in.
I simply want to remove that restriction. There is another view that looks the same except it's for Public and shows all the same data but not linked. (the data are pdf files).
On the authenticated display, next to Access in the Basic Settings it has: authenticated user. If I click that user role (not the gear for options), then I'm allowed a list of:
Domain
None
Permission
Role
…for access restrictions. I click "None", save. But, the links are not there as an anon visitor. Same if I try by changing the user to Anonymous User. Note: In the permissions, anon has the right to see webfm attachments.
I noticed the url is like: documents-public or documents-auth so I made it just documents. No luck.
I visited the actual custom-page-type which puts the View in a content pane. I re-ordered the variants, removed all Selection Rules and that didn't do anything either.
Flushed all caches.
Somewhere, the view is still only showing a view based on whether a user is authenticated or not even though I've removed the access (it says "unrestricted" next to access) on both displays and removed all selection rules on the actual page.
I'm stuck where else to look.
The setting you're changing (Access restrictions) is for the entire page - the page URL will return a 403 error if the criteria are met.
As to where the logic is to display/not display the link, four things come to mind:
If the "view mode" is set to node or teaser, it could be in the node template file.
The logic might be in a specific view template (click on the theme information link and see if any of the templates have been overridden).
The developer might have user Views Custom Fields to put the logic directly in the fields.
The linked content is actually restricted.
I'm sure there are other possibilities too. The main point here though is that if access was restricted for anon users, they would see a 403 error, not just some missing fields.

drupal give permission to access a content to authenticated user only

I am using a drupal 6. I need to restrict access to certain pages to my site for only the authenticated users. All these pages are having their own primary navigation parent menu, mouse hover on which it shows the sub menu to these pages. Once user clicks on it, it should show the page content if user is authenticated otherwise should show "Access Denied".
I tried to use Content Access module, though it restricts the access to the pages but it does not even show the menu link to anonymous user in menu list.
Is it possible to show menu in menu list, but on clicking on link it should show the access denied message of user is anonymous?
There are 2 ways you can go about this, the field permissions module if you just want to limit to specific fields or you can make a PHP block, call global $user within it, and if the user's role doesn't match on the node type for who you need to be, then call drupal_access_denied()
http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_access_denied/6
The block method is going to be much more efficient because you won't have to configure a billion checkboxes if you have a lot of fields and because if you make the block within a custom module, it will be exportable easily to other Drupal sites.

Drupal 7: Adding a 'Add New Listing' (Create Content) Link on Local Tasks Menu

I am working on making user pages for a certain type of user who can add/edit/delete content on my Drupal site. I've figured out how to use Views to create a 'Manage Listings' tab which appears on the user's profile, now I need to make another Local Task tab (or any kind of link) that allows the user to add new content.
I tried just adding a header to the view using basic markup text that contains:
Add New Listing
But because the link is displayed from the 'users/admin/' page, the link ends up bringing them to 'users/admin/node/add/' which doesn't exists (obviously). How can I create a create content link without messing up the path?
Below is a visual for help:
Please excuse the fact that this is a very simple question - this is my first attempt at building a Drupal site.
use /node/add instead because then it is relative to url instead.

wordpress user management, how to assign specific page to each user?

I want to create pages in WordPress, which should show to a specific user only not for specific role.
if a page is created for a specific user like "john". it should be viewed by only john, no other users could not see that page.
My Questions are:
How to create a page for a specific user? (from admin).
Note: while creating page we should assign that page to specific user like "john".
Is there any plugins for this?
Is there any way to do this.
-Srikanth.
I know that it is a bit late but still want to answer in case you need. Try to use http://wordpress.org/extend/plugins/user-specific-content/ plugin. You can customize your pages.
Just an idea:
Why not make a page template for that page? get current user id in the template then show the details depends on the user id? You can check is_user_logged_in() and pull all contents under the if statement and under the else statement you can redirect the user to the login page or just show the message to logged in.
Let me know if everything is clear. Thanks!
This can be done with ease using nav menu plugin and roles creator plugin.you can create roles with names of your clients and show menu items of user pages to specific roles/person

Resources