0

I want to make my site accessible to logged-in users. How can I achieve this?

1
  • What do you want anonymous users to see? Where should people log in? Jan 3 '17 at 9:47
3

There is a permission in the permissions list called "View published content". The permissions are set under /admin/people/permissions. You can remove this permission from the Anonymous user.

If you want to show some pages but not all of them, more granular access controls can be set up with Content Access.

Custom 404 and 403 pages can be set to use any content on your site, using settings at /admin/config/system/site-information (in Drupal 7). Sidebars are automatically hidden on 404 and 403 pages but if there are any other blocks (such as menus) you want to hide, you can control which roles see those on their block config pages.

The content of these nodes will also be unaccessible to anonymous users unless you install Content Access and make at least th 403 page allowed for anonymous users. I suggest allowing the 404 page too. Otherwise, you can still get info through if you put it in a node-specific template for your custom 404 page.

The login block can also be invoked programmatically in a tpl.php file with the code from this d.o comment or it can be shown to anonymous users via the block settings.

2
  • Thanks, It works. I unchecked the "View published content". when I visit my site ,Access denied Message showed. But I can also see the Menus. Can I edit the Message for more user-friendly. or Could I show a login dialog when the unauthorized user visit the site>
    – googlg
    Feb 17 '13 at 8:32
  • Yes, you can do that. I'll add info to my answer.
    – beth
    Feb 17 '13 at 17:55
0

First solution

It can be a combo of the permission "View published content" and LoginToboggan.
In LoginToboggan, there is setting to put login form on access denied page as well. "Present login form on access denied (403)". So every anonymous user will see a login form whenever they visit the site.

Second solution

See this comment, which is valid.

I think setting the "Default 403 (access denied) page" to the login page is a bad idea because just because someone has access denied does not mean they are not logged in; they may just not have permission to view that particular page.

A better method is to put a little code in your themes template.php.

function YOUR_THEME_NAME_preprocess_page(&$variables) {
    if(!$variables['user']->uid && arg(0)!='user' && arg(1)!='login') {
        drupal_goto('user/login');
    }
 }

Third solution

See this answer.

Not the answer you're looking for? Browse other questions tagged or ask your own question.