I am trying to set up a password protected Drupal site that allows users to only view the home page unless they are logged in. I have searched the forums and haven't found a solution. Is this possible? I am pretty new to Drupal.

Comments

scrypter’s picture

This tutorial may not be exactly what you want but should get you started, the bit about "Logging into the extranet". You can surround the login part with home page detail.

http://www-128.ibm.com/developerworks/ibm/library/i-osource10/

BTW, all these IBM tutorials are excellent.

www.scryptik.com - Javascript editor with syntax error checking

www.purpleoar.co.nz/scryptik - Javascript editor with syntax error checking
www.purpleoar.co.nz - Web development, Drupal consultancy

jrc’s picture

Stephtek,

Yes, it is possible. The easy way to accomplish this task is to hack page.tpl.php in your themes// directory. If you want to ensure that any unauthenticated user receives a simple login page, do the following:

In page.tpl.php, add the following code to the top of the file

	global $user;
        // if the user is not logged in, the user will have a uid of 0...
	if (!$user->uid) {
		include 'page-login.tpl.php';
		return;
	}

Create a page-login.tpl.php file in whatever template you wish in your themes// directory. Add the following form to the body of the page

...

<?php global $user;
if (!$user->uid) : ?>
<h2>Please Login</h2>
<form action="<?php print base_path(); ?>user/login"  method="post" id="loginform" >
<label id="edit-name"><span>user:</span></label><input type="text" maxlength="60" name="edit[name]" id="edit-name"  size="15" value="" class="form-text required" /><br />
<label id="edit-pass"><span>pass:</span></label><input type="password" maxlength="" name="edit[pass]" id="edit-pass"  size="15"  class="form-text required" /><br />
<input type="submit" name="op" value="Log in"  class="form-submit" />
<input type="hidden" name="edit[form_id]" id="edit-form_id" value="user_login"  /></form>
<?php endif; ?>
...

That should do it. You'll, of course, want to tweak the login page to look like something a client would want to login to...

peddyfab’s picture

Hello J,
Thanks for your code..really, i tried it but i couldn,t get it right.Maybe i didn,t placed the file the way it suppose to be. In page.tpl.php i opened it and added below code ontop of the codes in the file.

global $user;
// if the user is not logged in, the user will have a uid of 0...
if (!$user->uid) {
include 'page-login.tpl.php';
return;
}
later i created a login.tpl.php file on my theme directory and placed this code in it
...

 global $user;
if (!$user->uid) : 

Please Login

print base_path(); user/login" method="post" id="loginform" >
user:
pass:

endif;
...
i coldn,t get any result...pls i will so much appreciate if you can indicate step by step on how to place this code.
Thanks and regards.
fab

nancydru’s picture

Use one of the Taxonomy Control (or _lite) modules, or even the Menu_By_Role module. No coding needed.

Nancy W.
now running 4 sites on Drupal so far

laura s’s picture

Disable "access content" for anonymous users.

Laura
_____ ____ ___ __ _ _
design, snap, blog

_____ ____ ___ __ _ _
Laura Scott :: design » blog » tweet

nancydru’s picture

Wouldn't that block the front page too?

Nancy W.
now running 4 sites on Drupal so far

vm’s picture

Dropping that code in rather then using a module is less resource intensive. When it can be done in code at the theme level, rather then a module it can be considered a beneift over using a module.

laura s’s picture

Your login block will still appear along with the logo and site name.

Laura
_____ ____ ___ __ _ _
design, snap, blog

_____ ____ ___ __ _ _
Laura Scott :: design » blog » tweet

stephtek’s picture

That is what I ended up doing and just mde the 403 page custom. It worked great!