How to lock anonymous users out of the site, give them access to just one home page, and present the real home page upon login?

Events happening in the community are now at Drupal community events on www.drupal.org.
estephan500's picture

Hi folks --

I'm building a site where I want anonymous users to access none of the site's real content until they log in.

However, when a user first comes to the site prior to login, I'd like them to have a decent page telling them to log in, and where they can see the login block.

My current method includes:

-- the Taxonomy Access module (so that I can use a category tag to specify that one of the pages will in fact be viewable by un-authenticated people, that's the page I'll make my home page for the not-yet-logged-in people)

-- secondly, the Front Page module (http://drupal.org/project/front) which allows me to specify one front page for authorized people and another front page for anonymous people.

All of this basically functions ok, with just one flaw:

when a new user comes to my site:
(1) they are correctly directed by the Front Page module to the page that I made to tell anonymous people to log in.
(2) then the person types their login information into the login box and hits submit.
(3) problem: now that they just logged in, nothing automatically directs that user to go zap directly to the Front Page again. If it did, then I assume that the front page module would naturally kick them to the front page for authenticated people, and I'd be done. But it doesn't -- it just says "great, you logged in, we'll leave you right at the page where you issued the log-in command." Which effectively leaves them at a page that has language about how they need to log in to see the site.

Does anyone know either (1) how to tell the login block to immediately kick a user that just logged in either to the front page or a specific page (I with that front page did this, I am indeed using the current version, 1.9)
... or (2) a graceful way of giving a single friendly "you gotta log in" page for anonymous users, and when they log in, immediately redirects them to a more appropriate page (i.e. the real front page)?

huge thanks for any ideas --

Eric

Comments

Login Destination?

chyatt's picture

You could try the Login Destination module to achieve the redirection:

http://drupal.org/project/login_destination

C

ContentAccess module?

damienmckenna's picture

You could try the Content_Access module to assign permissions accordingly. You'd have to create a content type for just the homepage, but it should work.

one approach

christefano's picture

What you describe sounds much like what Facebook does. They don't really have a front page -- just a login form that then redirects to the intended page. Replicating it is easy. Here's one approach that uses a little custom theming and a module or two.

  1. Turn off the "access content" permission for anonymous users. Unless you're using node access modules elsewhere, I'd just leave them out.

  2. Set the default home page in admin/settings/site-information to 'front' or something similar.

  3. Create a "logged in home page" that's at a new path (like 'home'). This can be done with Panels but I'd rather create a node-home.tpl.php file for the site's theme.

  4. Create a page-front.tpl.php file for your site's theme and style it however you want. Use global $user; if ($user->uid) to see if visitors are anonymously browsing and show them a login form. If users are already logged in, have them redirected to the logged in home page (the one at 'home').

  5. Use something like Login Destination to send logged in members directly to the logged in home page when logging in. Without it, an unnecessary redirect will send visitors who log in from the front page (which is styled with the page-front.tpl.php file) to the home page (which is styled with the page-home.tpl.php file). With it, members will always be sent to the logged in home page.

  6. I don't think installing LoginToboggan or CustomError and setting 'front' as the 403 page will work when the "access content" permission is disabled. It's worth trying, though, so that the front page will be shown instead of an "access denied" message when anonymous visitors land on pages that they don't have access to. The trick is to be sure that there isn't a node aliased to the 'front' path.

thank you!

estephan500's picture

I really appreciate the help you guys gave above. I will work with that info and will come back if I still have questions!

thanks so much -eric

I have done essentially the

lee20's picture

I have done essentially the exact same thing that you have, where anonymous users must login and using the front page module to help direct them to the login. I face the problem of having to ensure all of my panels and views do not permit access to anon users.

Anyhow, I solved the login redirect by assigning a custom Redirect to URL action to the "After a user signs in" trigger. I set this to <front>, so immediately after they log in they are directed to the front page module and then redirected from there.

SecureSite

ebrittwebb's picture

I've done this using SecureSite. It seems that would fit your needs quite well in a pretty simple approach.

Erik Britt-Webb
drupal@ebrittwebb.com

Privacy by role module

papapep's picture

Lets you define per role and content type permissions. If you set all content type defaults to be hidden to anonymous users, you've done it. This is how I'm building our business intranet, just showing the "user" node to the world, to let the users login, and when they're in the site they view just the per role allowed content.

I have the same problem

bjste's picture

I'm trying to do the same thing:
anonymous user should be directed to my "login page"
authenticated users to "home"
When logging in also redirected to "home".

However, I don't seem to be able to get the frontpage module to work.
I am able to redirect my logo to another page, but the other settings for frontpages for anonymous and authenticated does not work.
I only get an Access denied at my homepage and at the login page the text appears as well.

Could anyone please try to explain a bit more on how to work with this module?