I have a site that is for internal company use only, and I need to lock down the access so anonymous users can't access anything except the login page.

Currently it seems I need to set access per role for views etc to do this, but is there a complete solution that will block for anonymous without having to set views etc one by one?

Thanks in advance.

Comments

smitarai’s picture

You are in luck, got the same request from a client regarding this sometime back...

Heres how to do this

function modulename_page_build(&$page){
global $user;
//Check if uid==0
//arg(0)=='user'
//is front page
if($user->uid==0){
//User has access to the front page, or the user page
if(arg(0)!='user' && !drupal_is_front_page()){
//Post a message here with drupal_set_message() so that user knows why he has to login.
drupal_goto('user');
}
}
}

P.S->Wrote this on the fly, so there are bound to be syntax errors.