Is there any way to hide the login form?

Comments

rszrama’s picture

If you're referring to the login block on the left side of the screen, just browse to Administer > Site building > Blocks and change the settings. If that's not what you mean, you're going to have to be more specific...

The LoginToboggan module also gives you the ability to collapse that form or just make it a link...

----------------------
Current Drupal project: http://www.ubercart.org

gotmikhail’s picture

Administer->Site Building->Blocks - just turn off (set Region to <none>) the User Login block.

That's how I did mine, then I just have a link to "/?q=user" without clean urls for a user to actually login.

I also use some php to use different features for anonymous vs. logged in users, mainly using if($user->uid){do stuff;}
or
if(!$user->uid){do stuff;}

boisebarbara’s picture

Thanks for your simple solution/advice. I knew there would be a simple way to do this. For those of you who wonder why you would want to hide the login block, there are many reasons, but one of the most obvious is when you want to make a dynamic site look static--in other words, you would have no need for users to login to use the many interactive features of drupal. I think there is great opportunity here for people who want a simple website and also want to be able to edit it online without having to use web editing tools, uploading via ftp, etc. Again, thanks.

jp.stacey’s picture

Administer->Site Building->Blocks - just turn off (set Region to ) the User Login block.

Be warned: if you do this then even if you have a different admin theme with the block appearing, then logins from the admin pages will still fail. I think it's because the submission of a login through Form API goes via the front-end theme, which doesn't instantiate the form on the page.

If you still want to log in using the admin block, then edit your frontend theme's block.tpl.php (stub it out from themes/engines/phptemplate/block.tpl.php if you don't already have it) and surround it with:

if (! ($block->module == "user" && $block->delta == "0")):
...
endif;

Omit the very last ?> if you find yourself facing white screens of death.

--
J-P Stacey, software gardener, Magnetic Phield

coyote83’s picture

You can create a login.php file like this:

<?php
/* Redirect to a different page in the current directory that was requested */
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = '?q=user/login';
header("Location: http://$host$uri/$extra");
exit;
?>

Put it in the same folder of index.php

Then if you want to login, you can simply access http://www.example.com/login.php. Not really useful but quite nice ;-)

Cainan’s picture

I disabled the standard login block,
disabled the 'logout' menu entry,
andd created a new block with teh following PHP code in it:

<?php
  global $user;
  if ($user->uid) {
?>
     <a href="?q=logout">Logout</a>
<?php
   }else {
?>
     <a href="?q=user/login">Login</a>
<?php
   }
?>

once you enable this block, you have a nice single link block that either says 'Login' or 'Logout', and redirects appropriately.

pugsly2147’s picture

Thanks for posting this! It was very helpful to me.

nguyenquocviet’s picture

Hi Cainan,

I tried to create a new block as your instruction using link admin/build/block/add and copied your code into Block Body. But it have not worked.

Could you please show me how I create aa new block?

Thanks
Nguyen Quoc Viet

webpotato’s picture

I installed the Login Menu module on my 5.x site

http://drupal.org/project/loginmenu

and set the login/logout menu items in my primary links, heavily weighted so that it shows up in the upper right corner of my pages.

Then I set the "User login" block that comes as the default to "Users cannot control whether or not they see this block" and set the page-specific visibility settings to php and included the following php code:

<?php
  // Only show if $match is true
  $match = false;

   // See if the following matches
  if (1 == 2) {
    $match = true;
  }

  return $match;
?>



As long as 1 remains unequal to 2, the User login block will not appear on the site.

I also did not like the way I was always redirected to "My Account" after logging in. My site's content is what I want users to see first, not their personal info, so I set it up to always redirect to the home page by hacking the user.module file as follows:
I changed

user_module_invoke('login', $form_values, $user);

    sess_regenerate();
    return 'user/'. $user->uid;
  }

to

user_module_invoke('login', $form_values, $user);

    sess_regenerate();
    return '';
  }



(about line 962)

Seems to work

lakbaytaodev’s picture

Hello Webpotato,

Thanks a lot for sharing this info. It really worked for me.

All the best,

Tata