1

I'm using IP-based login to give visitors in a private network access to some parts of my Drupal 6 site. This means that all users from this private network are logged in as the same user.

Theoretically, anyone accessing the site that way could change the user password, which is something I don't really want to allow. I tried the User Protect module, but that just doesn't work at all on my site. I suspect that it is just incompatible with the IP login module.

Ideally, I'd like to hide the /user page entirely from certain users. They shouldn't be able to access it and shouldn't be able to change their password or any other profile information.

How can I prevent access to the user profile?

1

You can do this with hook_menu_alter changing the access callback and access arguments for the relevant user menu items.

e.g

/**
 * Implements hook_menu_alter
 */
function MYMODULE_menu_alter(&$items){
  // Change user view and edit callbacks to be "administer users" access only.
  $items['user/%user/view']['access callback'] = 'user_access';
  $items['user/%user/view']['access arguments'] = array('administer users');
  $items['user/%user_uid_optional']['access callback'] = 'user_access';
  $items['user/%user_uid_optional']['access arguments'] = array('administer users');
  $items['user/%user_category/edit']['access callback'] = 'user_access';
  $items['user/%user_category/edit']['access arguments'] = array('administer users');
}

Clear menu cache to apply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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