I would like to change the "request new password" tab at user/login. (My users authenticate with an external LDAP server, so the "request new password tab" is confusing and inapplicable.)

Any suggestion on how to do this?

Comments

Christefano-oldaccount’s picture

You can create a custom module that overrides the page at user/password and display a node or something else instead. The Password Reset module does.

That's the approach I'd take. DesignWork's post below is good one and doesn't require overriding whole functions in user.module.

designwork’s picture

Hi xjm,

I would override the tab in your template.php

// function to override tabs
function phptemplate_removetab($label, &$vars) {
  $tabs = explode("\n", $vars['tabs']);
  $vars['tabs'] = '';

  foreach($tabs as $tab) {
    if(strpos($tab, '>' . $label . '<') === FALSE) {
      $vars['tabs'] .= $tab . "\n";
    }
  }
}

Warm regards from cologne

Dirk
And then in your function _phptemplate_variables($hook, $vars = array()) { you search the hook user and put this in it:

// remove a tab in the hook user
	  		if (arg(0)=="user"){
			zen_removetab('request new password' ,$vars);
			
		}//end removing tab
xjm’s picture

This is what I ended up doing, thanks! (Unfortunately none of the modules suggested in this thread seemed to do the trick).

I modified the removetab function a little, as follows:

function phptemplate_removetab($label, &$vars) {
  $tabs = explode("\n", $vars['tabs']);
  $new_tabs =  array();
  $vars['tabs'] = "";

  foreach ($tabs as $tab) {
    // add the tab to the new tabs if it's not the one we're removing
    if (stripos($tab, '>' . $label . '<') === FALSE) {
      $new_tabs[] = $tab;
    }
  }

  $new_tabs_string = implode ($new_tabs,"\n");

  //only display if there is more than one tab
  //there's probably a more elegant way of doing this
  $pieces = explode("</li>",$new_tabs_string);
  if (sizeof($pieces) > 2) {
    $vars['tabs'] = $new_tabs_string;
  }
}

I made the search for the tab label case-insensitive and set it to only display tabs if there was more than one. In retrospect I should have checked whether the only tab was indeed an active tab before hiding it.

For anyone else who is trying to do this, another good idea is using the path access module to restrict access to user/password. This doesn't hide the tab by itself (despite that I seem to remember it doing so in 4.7), but it will prevent users from resetting their password and "unsynching" their drupal acct from the LDAP one.

ms1’s picture

I want to hide a tab in my user-profile edit page.

I did exactly as shown here but not getting ti hide. Please help me as I am not at all comfortable with php.

This is what I did
1. Put the code below in my template.php file.

function phptemplate_removetab($label, &$vars) {
  $tabs = explode("\n", $vars['tabs']);
  $vars['tabs'] = '';

  foreach($tabs as $tab) {
    if(strpos($tab, '>' . $label . '<') === FALSE) {
      $vars['tabs'] .= $tab . "\n";
    }
  }
}

2. then in the template.php file itself, I placed this

  if ($hook =='user') {
     //remove a tab in the hook user
    if ((arg(0)=="user") && (arg(2)=="edit")){
	  phptemplate_removetab('Personal Information', $vars);
    }//end removing tab phptemplate_removetab
  }  

in the function
function _phptemplate_variables($hook, $vars)

But nothing is happening, please tell me what am I doing wrong?

Thanks & Regards

tm’s picture

i have been told that this functionality, which used to be in ldap_integration, was taken out due to duplication of those functions with the user protect module. have not tried it myself, though.

edit: maybe not. hrmpp! i kinda need this functionality. it was in ldap_integration v5.1.2...

pgo-1’s picture

First, I tried this module: Sympal Password Hijack which as far as I can tell does nothing. I had to create an info file for it so I could activate it, but then it did nothing - no settings, nothing.

I'm getting some success by using a combination of:

http://drupal.org/node/115159#comment-196079 and http://drupal.org/node/180295#comment-276944

I created my own module:

/**
* Implementation of hook_help().
*/
function remove_password_request_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Makes login block collapsible');
  }
}

/**
* Implementation of hook_form_alter().
*/
function remove_password_request_form_alter($form_id, &$form) {
  if ($form_id == 'user_login_block'){
       unset($form['links']);
       $items = array();
       if (variable_get('user_register', 1)) {
           $items[] = l(t('Create new account'), 'user/register', array('title' => t('Create a new user account.')));
       }
       $form['links'] = array('#value' => theme('item_list', $items));
  }
}

/**
* Implementation of hook_menu().
*/
function remove_password_request_menu() {
  $items[] = array(
    'path' => 'user/password',
    'title' => t('Menu item disabled'),
    'callback' => 'drupal_not_found',
    'type' => MENU_CALLBACK
  );
  return $items;
}

And the info file:

; $Id$
name = "Remove Password Request"
description = "Removes the 'Request New Password' link from the login form and disables the user/password menu item."

The only drawback so far is that the "request new password" tab still appears at "/user". I'll try implementing this thread's fix to fix it (EDIT: not working so far).

Maybe just removing it from the login block will be enough...

pgo-1’s picture

I saw in another thread that http://drupal.org/project/password-reset would do what I wanted.

I uninstalled my custom module above, installed password reset, found it didn't do what I wanted, uninstalled it (had to manually remove the database tables, sigh), and re-installed my custom module.

Now the Request New Password tab is gone when I go to /user and /user/login

Wierd!

EDIT: Just re-tested and uninstalled and reinstalled my module again and I'm still not seeing the tab...I'm going to try this process on a fresh install when I get home from work and see if it really works.

pgo-1’s picture

I just did a fresh install at home (Drupal 5.3). First thing I did was set it so that only administrators can add users (gets rid of the "Create an account" link/tab), then I created the custom module pasted above (named remove_password_request), which completely got rid of the request new password link and tab - and going to user/password results in a page not found error!

Don't think anything else is missing.

Not sure I completely understand how the code above works (new to Drupal), but it seems to.

jhall89’s picture

I upgraded my site to 5.5 and now this custom module doesn't work. Is anyone else having this problem, or is it just something wrong with my setup? I get no errors. It just doesn't work...:(

ttosttos’s picture

Beyond just removing the tab, you also want to remove all entry points into user/password. Error message on login form includes a link ("have you forgotten your password?). Also a user could enter directly the user/password path. The "No Request new password" module should help with those (http://drupal.org/project/noreqnewpass).

xjm’s picture

Thanks for the link... this module didn't exist when I originally looked into this issue, so I did a lot of theming to get rid of the various password resetting links. I'll test the module when I get the chance!

syoumans’s picture

Nice suggestion, this worked like a champ ... and it has an option for disabling a user's ability to change their password. Perfect!

I'm using OpenID, so I don't want users changing their password on the Drupal-based system.